功能
change file access and modification times
更新文件的访问时间和修改时间备注:
touch
命令也通常用来创建新文件
用法
-
touch file
- 创建新文件
$ touch file; ls
file
$ touch file1 file2 file3; ls
file1 file2 file3
-
touch file
- 更新文件的访问、修改时间
$ touch file; stat file
File: "file"
Size: 0 FileType: Regular File
Mode: (0644/-rw-r--r--) Uid: ( 501/zhangjian) Gid: ( 20/ staff)
Device: 1,7 Inode: 3883002 Links: 1
Access: Fri Jul 27 11:03:15 2018
Modify: Fri Jul 27 11:03:15 2018
Change: Fri Jul 27 11:03:15 2018
$ touch file; stat file
File: "file"
Size: 0 FileType: Regular File
Mode: (0644/-rw-r--r--) Uid: ( 501/zhangjian) Gid: ( 20/ staff)
Device: 1,7 Inode: 3883002 Links: 1
Access: Fri Jul 27 11:03:55 2018
Modify: Fri Jul 27 11:03:55 2018
Change: Fri Jul 27 11:03:55 2018
-
touch -a file
- 只更新文件的访问时间
$ touch file; stat file
File: "file"
Size: 0 FileType: Regular File
Mode: (0644/-rw-r--r--) Uid: ( 501/zhangjian) Gid: ( 20/ staff)
Device: 1,7 Inode: 3883626 Links: 1
Access: Fri Jul 27 11:16:09 2018
Modify: Fri Jul 27 11:16:09 2018
Change: Fri Jul 27 11:16:09 2018
$ touch -a file; stat file
File: "file"
Size: 0 FileType: Regular File
Mode: (0644/-rw-r--r--) Uid: ( 501/zhangjian) Gid: ( 20/ staff)
Device: 1,7 Inode: 3883626 Links: 1
Access: Fri Jul 27 11:16:28 2018
Modify: Fri Jul 27 11:16:09 2018
Change: Fri Jul 27 11:16:28 2018
-
touch -m file
- 只更新文件的修改时间
$ touch file; stat file
File: "file"
Size: 0 FileType: Regular File
Mode: (0644/-rw-r--r--) Uid: ( 501/zhangjian) Gid: ( 20/ staff)
Device: 1,7 Inode: 3883685 Links: 1
Access: Fri Jul 27 11:18:31 2018
Modify: Fri Jul 27 11:18:31 2018
Change: Fri Jul 27 11:18:31 2018
$ touch -m file; stat file
File: "file"
Size: 0 FileType: Regular File
Mode: (0644/-rw-r--r--) Uid: ( 501/zhangjian) Gid: ( 20/ staff)
Device: 1,7 Inode: 3883685 Links: 1
Access: Fri Jul 27 11:18:31 2018
Modify: Fri Jul 27 11:19:13 2018
Change: Fri Jul 27 11:19:13 2018
Mac用户请使用stat -x file
来查看文件状态
网友评论