栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux如何使用命令更新文件目录时间

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux如何使用命令更新文件目录时间

  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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/589134.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号