当前位置: 首页 新闻资讯 游戏新闻

cmd命令查看目录文件|Linux如何使用命令更新文件目录时间

  • 08-13
  • 7135

  Linux系统中touch命令是更新目录或文件进行时间日期的命令,不过还有许多用户对touch命令还不太清楚,因此,小编今天就给大家介绍一下touch命令的用法吧。

  touch命令使用技巧:

  名称:touch

  使用权限:所有使用者

  使用方式:

  touch [-acfm]

  [-r reference-file] [--file=reference-file]

  [-t MMDDhhmm[[CC]YY][.ss]]

  [-d time] [--date=time] [--time={atime,access,use,mtime,modify}]

  [--no-create] [--help] [--version]

  file1 [file2 。]

  说明:

  touch 指令改变档案的时间记录。 ls -l 可以显示档案的时间记录。

  参数:

  a 改变档案的读取时间记录。

  m 改变档案的修改时间记录。

  c 假如目的档案不存在,不会建立新的档案。与 --no-create 的效果一样。

  f 不使用,是为了与其他 unix 系统的相容性而保留。

  r 使用参考档的时间记录,与 --file 的效果一样。

  d 设定时间与日期,可以使用各种不同的格式。

  t 设定档案的时间记录,格式与 date 指令相同。

  --no-create 不会建立新档案。

  --help 列出指令格式。

  --version 列出版本讯息。

  使用范例:

  实例一:创建不存在的文件

  命令:

  touch log2012.log log2013.log

  输出:

  [root@localhost test]# touch log2012.log log2013.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  如果log2014.log不存在,则不创建文件

  [root@localhost test]# touch -c log2014.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  实例二:更新log.log的时间和log2012.log时间戳相同

  命令:

  touch -r log.log log2012.log

  输出:

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

  [root@localhost test]# touch -r log.log log2012.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

返回顶部