linux 中touch命令修改atime和mtime

1、测试数据

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 14:27:12.494846760 +0800
Modify: 2022-02-01 12:30:00.000000000 +0800
Change: 2022-03-27 14:27:01.926886078 +0800
 Birth: -

 

2、touch -a :atime更新到系统当前时间

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 14:27:12.494846760 +0800
Modify: 2022-02-01 12:30:00.000000000 +0800
Change: 2022-03-27 14:27:01.926886078 +0800
 Birth: -
root@ubuntu01:/home/test# date
2022年 03月 27日 星期日 14:28:14 CST
root@ubuntu01:/home/test# touch -a a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 14:28:20.006636889 +0800
Modify: 2022-02-01 12:30:00.000000000 +0800
Change: 2022-03-27 14:28:20.006636889 +0800
 Birth: -

 

3、touch -m: mtime修改到当前时间

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 14:28:20.006636889 +0800
Modify: 2022-02-01 12:30:00.000000000 +0800
Change: 2022-03-27 14:28:20.006636889 +0800
 Birth: -
root@ubuntu01:/home/test# date
2022年 03月 27日 星期日 14:29:31 CST
root@ubuntu01:/home/test# touch -m a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 14:28:20.006636889 +0800
Modify: 2022-03-27 14:29:36.917365925 +0800
Change: 2022-03-27 14:29:36.917365925 +0800
 Birth: -

 

3、touch -c:全部修改到当前时间

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 14:30:48.772042772 +0800
Modify: 2022-03-27 14:29:36.917365925 +0800
Change: 2022-03-27 14:29:36.917365925 +0800
 Birth: -
root@ubuntu01:/home/test# date
2022年 03月 27日 星期日 14:32:17 CST
root@ubuntu01:/home/test# touch -c a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 14:32:22.810687351 +0800
Modify: 2022-03-27 14:32:22.810687351 +0800
Change: 2022-03-27 14:32:22.810687351 +0800
 Birth: -

 

4、touch -d “指定时间”

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 14:34:12.697482322 +0800
Modify: 2022-03-27 14:34:53.213112565 +0800
Change: 2022-03-27 14:34:53.213112565 +0800
 Birth: -
root@ubuntu01:/home/test# date
2022年 03月 27日 星期日 14:35:24 CST
root@ubuntu01:/home/test# touch -d "10:20" a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 10:20:00.000000000 +0800
Modify: 2022-03-27 10:20:00.000000000 +0800
Change: 2022-03-27 14:35:32.324785145 +0800
 Birth: -

 

5、atime修改到指定时间

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 10:20:00.000000000 +0800
Modify: 2022-03-27 10:20:00.000000000 +0800
Change: 2022-03-27 14:35:32.324785145 +0800
 Birth: -
root@ubuntu01:/home/test# touch -at 200910112200 a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2009-10-11 22:00:00.000000000 +0800
Modify: 2022-03-27 10:20:00.000000000 +0800
Change: 2022-03-27 14:41:18.442652519 +0800
 Birth: -

 

6、mtime修改到指定时间

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2009-10-11 22:00:00.000000000 +0800
Modify: 2022-03-27 10:20:00.000000000 +0800
Change: 2022-03-27 14:41:18.442652519 +0800
 Birth: -
root@ubuntu01:/home/test# touch -mt 201510101230 a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2009-10-11 22:00:00.000000000 +0800
Modify: 2015-10-10 12:30:00.000000000 +0800
Change: 2022-03-27 14:43:20.338074499 +0800
 Birth: -

 

如何只修改 ctime?

 

posted @ 2022-03-27 14:30  小鲨鱼2018  阅读(709)  评论(0编辑  收藏  举报