文章目录
命令介绍
- 命令介绍
- 常用选项
- 命令示例
- (一)创建空文件
- (二)批量创建文件
- (三)修改文件的访问时间
touch 命令有两个功能:一是用于把已存在文件的时间戳更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来;二是用来创建新的空文件。
touch 命令会根据当前的系统时间更新指定文件的访问时间和修改时间。如果文件不存在,将会创建新的空文件,除非指定了”-c”或”-h”选项。
注意:在修改文件的时间属性的时候,用户必须是文件的属主,或拥有写文件的访问权限。
常用选项 选项说明-a改变档案的读取时间记录-m改变档案的修改时间记录-r使用参考档的时间记录,与 --file 的效果一样-c不创建新文件-d设定时间与日期,可以使用各种不同的格式-t设定档案的时间记录,格式与 date 命令相同–no-create不创建新文件–help显示帮助信息–version列出版本讯息 命令示例 (一)创建空文件[root@linuxcool ~]# touch file.txt
(二)批量创建文件
[root@linuxcool ~]# touch file{1..5}.txt
[root@linuxcool ~]# ls
file1.txt file2.txt file3.txt file4.txt file5.txt
(三)修改文件的访问时间
[root@linuxcool ~]# stat file.txt
File: file.txt
Size: 0 Blocks: 0 IO Block: 512 regular empty file
Device: 2h/2d Inode: 87538717757135273 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 1000/ root) Gid: ( 1000/ root)
Access: 2019-04-07 00:25:34.729216500 +0800
Modify: 2019-04-07 00:25:34.729216500 +0800
Change: 2019-04-07 00:25:34.729216500 +0800
Birth: -
[root@linuxcool ~]# touch -a file.txt
[root@linuxcool ~]# stat file.txt
File: file.txt
Size: 0 Blocks: 0 IO Block: 512 regular empty file
Device: 2h/2d Inode: 87538717757135273 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 1000/ root) Gid: ( 1000/ root)
Access: 2019-04-07 00:26:13.004116000 +0800
Modify: 2019-04-07 00:25:34.729216500 +0800
Change: 2019-04-07 00:26:13.004116000 +0800
Birth: -