Linux学习笔记9touch命令使用

NAME
       touch - change file timestamps --改变文件的时间记录

SYNOPSIS
       touch [OPTION]... FILE...

DESCRIPTION
       Update  the  access and modification times of each FILE to the current
       time. --使用touch指令可更改文件或目录的日期时间,包括存取时间和更改时间。

       Mandatory arguments to long options are mandatory  for  short  options
       too.

       -a     change only the access time --改变文件的读取时间记录

       -c, --no-create
              do not create any files --假如目标不存在,不会创建新的问题。

       -d, --date=STRING
              parse STRING and use it instead of current time
  --设定时间与日期的格式,而非当前时间。
       -f     (ignored) --不使用,为了与其他Unix系统相兼容而保留

       -m     change only the modification time --只是更改变动时间

       -r, --reference=FILE
              use this file鈥檚 times instead of current time
  --把指定文件或目录的日期时间,统统设成和参考文件或目录的日期时间相同
       -t STAMP
              use [[CC]YY]MMDDhhmm[.ss] instead of current time
  --设定时间与日期的格式,而非当前时间。

命令在什么时候使用。这里我知道可以使用它来建立空文件。
如:
[OK_008@CentOS4 ~]$ touch aa --建立一个aa的文件
[OK_008@CentOS4 ~]$ ls -l --Full-time --在Linux中大小写是很敏感的,就如c语言一样。
ls: unrecognized option `--Full-time'
Try `ls --help' for more information.
[OK_008@CentOS4 ~]$ ls -l --full-time --显示列表
total 12
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:11:49.000000000 +0800 aa
drwxrwxr-x  2 OK_008 OK_008 4096 2007-09-28 17:05:35.000000000 +0800 OK008Filed
[OK_008@CentOS4 ~]$ touch {bb.txt,cc.txt,dd.txt}
[OK_008@CentOS4 ~]$ ls -l --full-time
total 24
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:11:49.000000000 +0800 aa
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:28.000000000 +0800 bb.txt
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:28.000000000 +0800 cc.txt
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:28.000000000 +0800 dd.txt
--注意这一行的时间
drwxrwxr-x  2 OK_008 OK_008 4096 2007-09-28 17:05:35.000000000 +0800 OK008Filed

[OK_008@CentOS4 ~]$ touch {bb,cc,dd} --touch命令还可以一次建立多个空文件
[OK_008@CentOS4 ~]$ ls -l --full-time
total 36
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:11:49.000000000 +0800 aa
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:52.000000000 +0800 bb
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:28.000000000 +0800 bb.txt
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:52.000000000 +0800 cc
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:28.000000000 +0800 cc.txt
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:52.000000000 +0800 dd
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:28.000000000 +0800 dd.txt
drwxrwxr-x  2 OK_008 OK_008 4096 2007-09-28 17:05:35.000000000 +0800 OK008Filed

[OK_008@CentOS4 ~]$ touch {dd.txt,ee.txt} --这里重新建立多个文件,注意的是dd.txt与上前面代码写dd.txt的时间显示。
[OK_008@CentOS4 ~]$ ls -l --full-time
total 40
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:11:49.000000000 +0800 aa
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:52.000000000 +0800 bb
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:28.000000000 +0800 bb.txt
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:52.000000000 +0800 cc
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:28.000000000 +0800 cc.txt
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:12:52.000000000 +0800 dd
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:13:13.000000000 +0800 dd.txt
--注意这一行的时间
-rw-rw-r--  1 OK_008 OK_008    0 2007-09-28 17:13:13.000000000 +0800 ee.txt
drwxrwxr-x  2 OK_008 OK_008 4096 2007-09-28 17:05:35.000000000 +0800 OK008Filed

[OK_008@CentOS4 ~]$
[OK_008@CentOS4 ~]$ rm aa bb bb.txt cc cc.txt dd dd.txt ee.txt
--删除刚才建立的几个空文件
[OK_008@CentOS4 ~]$ ls
OK008Filed

可能这一点就说明touch命令的作用,是于它的修改意义还得参考资料和实践中才能知道了。

--参考资料《Linux系统开发员》广东省Linux公共服务技术支持中心组编
          《Linux常用命令全集》Chinaitlab中国IT实验室

原文地址:https://www.cnblogs.com/wghao/p/925613.html