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

上一篇:BackTrack5使用硬盘安装的具体步骤

下一篇:Linux iis无法正常运行asp文件如何解决


Linuxtouch命令 Linux中Touch命令
Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器