Linux学习笔记9--touch命令使用

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实验室

posted @   ok_008  阅读(2542)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
给我写信
点击右上角即可分享
微信分享提示