touch命令格式如下:
touch [-acdmt] 文件參數(shù):
-a : 僅修改access time芝发。
-c : 如果文件不存在美莫,則不創(chuàng)建新文件桐愉。
-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已經(jīng)改變過來亮钦。
- 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也已經(jīng)修改過來。