touch命令可以用来生成空白文件,如果文件存在,则会修改文件的时间戳
生成100个空白文件
for one in {1..100} do touch "$one.txt"; done
如果我们只想更改文件的时间戳,那么可以使用以下参数
查看文件的时间
[root@MIO-2 touch]# stat 1.txt File: `1.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 131100 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2014-08-24 21:02:59.413991479 +0800 Modify: 2014-08-24 21:02:59.413991479 +0800 Change: 2014-08-24 21:02:59.413991479 +0800
-a 更改文件访问时间
[root@MIO-2 touch]# touch -a 1.txt [root@MIO-2 touch]# stat 1.txt File: `1.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 131100 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2014-08-24 21:10:41.776000093 +0800 Modify: 2014-08-24 21:02:59.413991479 +0800 Change: 2014-08-24 21:10:41.776000093 +0800
-m 只更改文件修改时间
[root@MIO-2 touch]# stat 1.txt File: `1.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 131100 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2014-08-24 21:10:41.776000093 +0800 Modify: 2014-08-24 21:11:31.921987604 +0800 Change: 2014-08-24 21:11:31.921987604 +0800
-d 指定更改的时间
可以使用任何标准的日期格式
需要注意的是,使用-d时,文件的状态更改时间(change)不会跟着改变
[root@MIO-2 touch]# touch -d '2000-10-01 10:00:00' -a 1.txt [root@MIO-2 touch]# stat 1.txt File: `1.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 131100 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2000-10-01 10:00:00.000000000 +0800 Modify: 2014-08-24 21:11:31.921987604 +0800 Change: 2014-08-24 21:12:50.798999816 +0800