Linux文件目录时间更新touch命令用法
发布时间:2022-06-15 15:04:47 所属栏目:教程 来源:互联网
导读:touch命令开始看成了权限命令后来发现touch命令是对目录或文件进行时间日期的一个更新操作了,下面来看一些简单的例子. 名称:touch 使用权限:所有使用者 使用方式: touch [-acfm] [-r reference-file] [--file=reference-file] [-t MMDDhhmm[[CC]YY][.ss]]
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 //phpfensi.com -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 实例三:设定文件的时间戳 命令:touch -t 201211142234.50 log.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 [root@localhost test]# touch -t 201211142234.50 log.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 2012-11-14 log.log 说明:-t time 使用指定的时间值 time 作为指定文件相应时间戳记的新值,此处的 time规定为如下形式的十进制数: [[CC]YY]MMDDhhmm[.SS] 这里,CC为年数中的前两位,即”世纪数”;YY为年数的后两位,即某世纪中的年数,如果不给出CC的值,则touch 将把年数CCYY限定在1969--2068之内.MM为月数,DD为天将把年数CCYY限定在1969--2068之内,MM为月数,DD为天数,hh 为小时数(几点),mm为分钟数,SS为秒数,此处秒的设定范围是0--61,这样可以处理闰秒,这些数字组成的时间是环境变量TZ指定的时区中的一个时 间,由于系统的限制,早于1970年1月1日的时间是错误的. (编辑:开发网_商丘站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐