touch
创建文件
更新旧文件的时间戳
用法:touch [选项]... 文件...
将每个文件的访问时间和修改时间改为当前时间。
不存在的文件将会被创建为空文件,除非使用-c 或-h 选项。
如果文件名为"-"则特殊处理,更改与标准输出相关的文件的访问时间。
长选项必须使用的参数对于短选项时也是必需使用的。
-a 只更改访问时间
-c, --no-create 不创建任何文件
-d, --date=字符串 使用指定字符串表示时间而非当前时间
-f (忽略)
-h, --no-dereference 会影响符号链接本身,而非符号链接所指示的目的地
(当系统支持更改符号链接的所有者时,此选项才有用)
-m 只更改修改时间
-r, --reference=文件 使用指定文件的时间属性而非当前时间
-t STAMP 使用[[CC]YY]MMDDhhmm[.ss] 格式的时间而非当前时间
--time=WORD 使用WORD 指定的时间:access、atime、use 都等于-a
选项的效果,而modify、mtime 等于-m 选项的效果
--help 显示此帮助信息并退出
--version 显示版本信息并退出
[root@shuai test]# touch a.txt 创建a.txt文件
[root@shuai test]# ls
1 2 3 a.txt dir1 dir2 dir3 dir4 dir5
[root@shuai test]# touch b.txt c.txt 同时创建b.txt和c.txt文件
[root@shuai test]# ls
1 2 3 a.txt b.txt c.txt dir1 dir2 dir3 dir4 dir5
[root@shuai test]#
[root@shuai test]# touch {d..g}.txt 序列创建文件
[root@shuai test]# ls
1 2 3 a.txt b.txt c.txt dir1 dir2 dir3 dir4 dir5 d.txt e.txt f.txt g.txt
查看文件的具体属性 stat +文件
-a 改变文件的时间戳
[root@shuai test]# stat a.txt
File: "a.txt"
Size: 0 Blocks: 0 IO Block: 4096 普通空文件
Device: fd00h/64768d Inode: 3477 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-19 07:38:22.764008306 +0800
Modify: 2017-11-19 07:38:22.764008306 +0800
Change: 2017-11-19 07:38:22.764008306 +0800
[root@shuai test]# touch -a a.txt
[root@shuai test]# stat a.txt
File: "a.txt"
Size: 0 Blocks: 0 IO Block: 4096 普通空文件
Device: fd00h/64768d Inode: 3477 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-19 07:44:06.265024063 +0800
Modify: 2017-11-19 07:38:22.764008306 +0800
Change: 2017-11-19 07:44:06.265024063 +0800
[root@shuai test]#
-m 更改修改时间
[root@shuai test]# touch -m a.txt
[root@shuai test]# stat a.txt
File: "a.txt"
Size: 0 Blocks: 0 IO Block: 4096 普通空文件
Device: fd00h/64768d Inode: 3477 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-19 07:44:06.265024063 +0800
Modify: 2017-11-19 07:46:33.528999550 +0800
Change: 2017-11-19 07:46:33.528999550 +0800
创建文件
更新旧文件的时间戳
用法:touch [选项]... 文件...
将每个文件的访问时间和修改时间改为当前时间。
不存在的文件将会被创建为空文件,除非使用-c 或-h 选项。
如果文件名为"-"则特殊处理,更改与标准输出相关的文件的访问时间。
长选项必须使用的参数对于短选项时也是必需使用的。
-a 只更改访问时间
-c, --no-create 不创建任何文件
-d, --date=字符串 使用指定字符串表示时间而非当前时间
-f (忽略)
-h, --no-dereference 会影响符号链接本身,而非符号链接所指示的目的地
(当系统支持更改符号链接的所有者时,此选项才有用)
-m 只更改修改时间
-r, --reference=文件 使用指定文件的时间属性而非当前时间
-t STAMP 使用[[CC]YY]MMDDhhmm[.ss] 格式的时间而非当前时间
--time=WORD 使用WORD 指定的时间:access、atime、use 都等于-a
选项的效果,而modify、mtime 等于-m 选项的效果
--help 显示此帮助信息并退出
--version 显示版本信息并退出
[root@shuai test]# touch a.txt 创建a.txt文件
[root@shuai test]# ls
1 2 3 a.txt dir1 dir2 dir3 dir4 dir5
[root@shuai test]# touch b.txt c.txt 同时创建b.txt和c.txt文件
[root@shuai test]# ls
1 2 3 a.txt b.txt c.txt dir1 dir2 dir3 dir4 dir5
[root@shuai test]#
[root@shuai test]# touch {d..g}.txt 序列创建文件
[root@shuai test]# ls
1 2 3 a.txt b.txt c.txt dir1 dir2 dir3 dir4 dir5 d.txt e.txt f.txt g.txt
查看文件的具体属性 stat +文件
-a 改变文件的时间戳
[root@shuai test]# stat a.txt
File: "a.txt"
Size: 0 Blocks: 0 IO Block: 4096 普通空文件
Device: fd00h/64768d Inode: 3477 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-19 07:38:22.764008306 +0800
Modify: 2017-11-19 07:38:22.764008306 +0800
Change: 2017-11-19 07:38:22.764008306 +0800
[root@shuai test]# touch -a a.txt
[root@shuai test]# stat a.txt
File: "a.txt"
Size: 0 Blocks: 0 IO Block: 4096 普通空文件
Device: fd00h/64768d Inode: 3477 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-19 07:44:06.265024063 +0800
Modify: 2017-11-19 07:38:22.764008306 +0800
Change: 2017-11-19 07:44:06.265024063 +0800
[root@shuai test]#
-m 更改修改时间
[root@shuai test]# touch -m a.txt
[root@shuai test]# stat a.txt
File: "a.txt"
Size: 0 Blocks: 0 IO Block: 4096 普通空文件
Device: fd00h/64768d Inode: 3477 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-19 07:44:06.265024063 +0800
Modify: 2017-11-19 07:46:33.528999550 +0800
Change: 2017-11-19 07:46:33.528999550 +0800
[root@shuai test]#