Linux touch修改文件的atime和mtime

2017-05-21  本文已影响0人  qianghaohao

touch命令格式如下:

touch [-acdmt] 文件参数:
-a : 仅修改access time。
-c : 如果文件不存在,则不创建新文件。
-d : 后面可以接日期,也可以使用 –date=”日期或时间”
-m : 仅修改modify time。
-t : 后面可以接时间,格式为 [YYMMDDhhmm]

示例文件的atime,mtime,ctime如下:

[haohao@localhost ~]$ stat touch_demo.txt 
  File: 'touch_demo.txt'
  Size: 13          Blocks: 8          IO Block: 4096   regular file
Device: 100f5c8h/16840136d  Inode: 89522413    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  haohao)   Gid: ( 1000/  haohao)
Access: 2017-05-21 19:51:45.702469010 +0800
Modify: 2017-05-21 19:51:45.702469010 +0800
Change: 2017-05-21 19:51:45.702469010 +0800
 Birth: -
[haohao@localhost ~]$ touch -c -a -t 201702051420.50 touch_demo.txt 
[haohao@localhost ~]$ stat touch_demo.txt 
  File: 'touch_demo.txt'
  Size: 13          Blocks: 8          IO Block: 4096   regular file
Device: 100f5c8h/16840136d  Inode: 89522413    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  haohao)   Gid: ( 1000/  haohao)
Access: 2017-02-05 14:20:50.000000000 +0800
Modify: 2017-05-21 19:51:45.702469010 +0800
Change: 2017-05-21 19:59:02.450468977 +0800
 Birth: -

可以看出atime已经改变过来。

[haohao@localhost ~]$ touch -c -m -t 201702051420.50 touch_demo.txt 
[haohao@localhost ~]$ stat touch_demo.txt 
  File: 'touch_demo.txt'
  Size: 13          Blocks: 8          IO Block: 4096   regular file
Device: 100f5c8h/16840136d  Inode: 89522413    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  haohao)   Gid: ( 1000/  haohao)
Access: 2017-02-05 14:20:50.000000000 +0800
Modify: 2017-02-05 14:20:50.000000000 +0800
Change: 2017-05-21 20:00:42.424468968 +0800
 Birth: -

可以看出mtime也已经修改过来。

上一篇 下一篇

猜你喜欢

热点阅读