曲径通幽论坛

标题: touch --- 建立文件与修改文件时间 [打印本页]

作者: beyes    时间: 2009-1-5 03:57
标题: touch --- 建立文件与修改文件时间
三个文件时间:
mtime
ctime
atime
三个时间的解释在: http://www.groad.net/bbs/read.php?tid=508

用法: touch [-acdmt] 文件
參數:
-a  :僅修訂 access time;
-c  :僅修改時間,而不建立檔案;
-d  :後面可以接日期,也可以使用 --date="日期或時間"
-m  :僅修改 mtime ;
-t  :後面可以接時間,格式為[YYMMDDhhmm]  



使用 -a 参数示例

[beyes@localhost ~]$ ls -l --time=atime pass.txt
-rwxr-xr-x 1 beyes beyes 161 01-05 03:39 pass.txt

[beyes@localhost ~]$ touch -a -t 0901040000 pass.txt
[beyes@localhost ~]$ ls -l --time=atime pass.txt
-rwxr-xr-x 1 beyes beyes 161 01-04 00:00 pass.txt     #已经修改为 09年01月04日00时00分


使用 -d 参数示例

[beyes@localhost ~]$ touch -d 0105 pass.txt
[beyes@localhost ~]$ ls -l
-rwxr-xr-x  1 beyes beyes  161 01-06 01:05 pass.txt


-d 参数使用的另一种形式

[beyes@localhost ~]$ ll pass.txt; ll --time=atime pass.txt; ll --time=ctime pass.txt
-rwxr-xr-x 1 beyes beyes 161 01-06 01:05 pass.txt
-rwxr-xr-x 1 beyes beyes 161 01-06 01:05 pass.txt
-rwxr-xr-x 1 beyes beyes 161 01-06 01:05 pass.txt
[beyes@localhost ~]$ touch -d "2 days ago" pass.txt
[beyes@localhost ~]$ ll pass.txt; ll --time=atime pass.txt; ll --time=ctime pass.txt
-rwxr-xr-x 1 beyes beyes 161 01-04 01:18 pass.txt
-rwxr-xr-x 1 beyes beyes 161 01-04 01:18 pass.txt
-rwxr-xr-x 1 beyes beyes 161 01-06 01:18 pass.txt





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2