Linux 文件管理 : touch 命令详解

touch命令有两个功能:一是用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来;二是用来创建新的空文件。

语法

touch(选项)(参数)

选项

-a:或--time=atime或--time=access或--time=use  只更改存取时间;
-c:或--no-create  不建立任何文件;
-d:<时间日期> 使用指定的日期时间,而非现在的时间;
-f:此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题;
-m:或--time=mtime或--time=modify  只更该变动时间;
-r:<参考文件或目录>  把指定文件或目录的日期时间,统统设成和参考文件或目录的日期时间相同;
-t:<日期时间>  使用指定的日期时间,而非现在的时间;
--help:在线帮助;
--version:显示版本信息。

touch命令不仅可以创建新文件,而且可以修改文件的时间属性;


备注:

1) -t选项的时间格式[[CC]YY]MMDDhhmm[.ss]说明:


2) touch命令的几点说明:


详解:

yexiang@ubuntu:<~>$ stat aaa.txt 
  File: 'aaa.txt'
  Size: 50              Blocks: 8          IO Block: 4096   regular file
Device: 900h/2304d      Inode: 61892202    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1006/ yexiang)   Gid: ( 1006/ yexiang)
Access: 2018-07-02 17:38:46.128616062 +0800
Modify: 2018-07-02 17:38:46.128616062 +0800
Change: 2018-07-02 17:38:46.128616062 +0800
 Birth: -
yexiang@ubuntu:<~>$ touch -a aaa.txt
yexiang@ubuntu:<~>$ stat aaa.txt    
  File: 'aaa.txt'
  Size: 50              Blocks: 8          IO Block: 4096   regular file
Device: 900h/2304d      Inode: 61892202    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1006/ yexiang)   Gid: ( 1006/ yexiang)
Access: 2018-07-02 17:39:23.674331346 +0800
Modify: 2018-07-02 17:38:46.128616062 +0800
Change: 2018-07-02 17:39:23.674331346 +0800
 Birth: -
yexiang@ubuntu:<~>$ vim aaa.txt
yexiang@ubuntu:<~>$ stat aaa.txt
  File: 'aaa.txt'
  Size: 50              Blocks: 8          IO Block: 4096   regular file
Device: 900h/2304d      Inode: 61892202    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1006/ yexiang)   Gid: ( 1006/ yexiang)
Access: 2018-07-02 17:39:49.815535422 +0800
Modify: 2018-07-02 17:38:46.128616062 +0800
Change: 2018-07-02 17:39:23.674331346 +0800
 Birth: -
yexiang@ubuntu:<~>$ touch -m aaa.txt 
yexiang@ubuntu:<~>$ stat aaa.txt    
  File: 'aaa.txt'
  Size: 50              Blocks: 8          IO Block: 4096   regular file
Device: 900h/2304d      Inode: 61892202    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1006/ yexiang)   Gid: ( 1006/ yexiang)
Access: 2018-07-02 17:39:49.815535422 +0800
Modify: 2018-07-02 17:42:07.601998929 +0800
Change: 2018-07-02 17:42:07.601998929 +0800
 Birth: -


猜你喜欢

转载自blog.csdn.net/yexiangcsdn/article/details/80887944