$ll new.txt
保證輸出:ls:無法訪問 new.txt:沒有那個(gè)文件或目錄
```$touch new.txt
$ll new.txt
-rw-r--r-- 1 root root 0 7 月 12 16:56 new.txt
如果此文件已經(jīng)存在的情況下。更改文件時(shí)間為當(dāng)前時(shí)間
```$touch new.txt
-rw-r--r-- 1 root root 0 7 月 12 16:57 new.txt
案例:更改文件時(shí)間為指定時(shí)間
$date
2015 年 07 月 12 日 星期日 16:59:10 CST
```$touch -t 11111111 new.txt $ll new.txt -rw-r--r-- 1 root root 0 11 月 11 2015 new.txt
分析:此處指定文件的時(shí)間格式為:yyyy(年)MM(月)DD(日)hh(時(shí))mm(分),省略在表示使用當(dāng)前系統(tǒng)的時(shí)間。
案例:將文件改正與別的文件相同的時(shí)間
```$ll new.txt
-rw-r--r-- 1 root root 0 7 月 12 17:03 new.txt
$ll /etc/passwd
-rw-r--r-- 1 root root 1804 6 月 10 23:27 /etc/passwd
$touch -r /etc/passwd new.txt
$ll new.txt
-rw-r--r-- 1 root root 0 6 月 10 23:27 new.txt
總結(jié):linux 中 touch 命令參數(shù)不常用,一般在使用 make 的時(shí)候可能會(huì)用到,用來修改文件時(shí)間戳,或者新建一個(gè)不存在的文件。
語法:touch [-acdmt] 文件參數(shù)
```$find /tmp -exec touch -t 11111111 {} \; $ll /tmp 總用量 12 drwxr-xr-x 2 root root 4096 11 月 11 2015 hidden -rw-r--r-- 1 root root 0 11 月 11 2015 new.txt drwxr-xr-x 2 root root 4096 11 月 11 2015 test -rwxr-xr-x 1 root root 385 11 月 11 2015 touch.sh
分析:可把 `/tmp` 下的所有文件和目錄都改變修改時(shí)間。
主要選項(xiàng)和作用
參數(shù) 作用 -a 僅修改文件的最后訪問時(shí)間 -c 僅修改時(shí)間,而不創(chuàng)建文件 -d 后面可以接日期,也可以使用 -date=” 如期或時(shí)間” -m 僅修改文件的修改時(shí)間 -t 后面可接時(shí)間,格式為 [yyyyMMDDhhmm]