Linux touch修改文件的atime和mtime

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: -
  • 1.修改上面示例文件的atime为:2017-02-05 14:20:50:
[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已经改变过来。

  • 2.修改上面示例文件的mtime为:2017-02-05 14:20:50:
[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也已经修改过来。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容