Linux 指令篇:檔案目錄管理--touch名稱:touch 使用權(quán)限:所有使用者 使用方式: 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 ...] 說(shuō)明: touch 指令改變檔案的時(shí)間記錄。 ls -l 可以顯示檔案的時(shí)間記錄。 參數(shù): a 改變檔案的讀取時(shí)間記錄。 m 改變檔案的修改時(shí)間記錄。 c 假如目的檔案不存在,不會(huì)建立新的檔案。與 --no-create 的效果一樣。 f 不使用,是為了與其他 unix 系統(tǒng)的相容性而保留。 r 使用參考檔的時(shí)間記錄,與 --file 的效果一樣。 d 設(shè)定時(shí)間與日期,可以使用各種不同的格式。 t 設(shè)定檔案的時(shí)間記錄,格式與 date 指令相同。 --no-create 不會(huì)建立新檔案。 --help 列出指令格式。 --version 列出版本訊息。 范例: 最簡(jiǎn)單的使用方式,將檔案的時(shí)候記錄改為現(xiàn)在的時(shí)間。若檔案不存在,系統(tǒng)會(huì)建立一個(gè)新的檔案。 touch file touch file1 file2 將 file 的時(shí)間記錄改為 5 月 6 日 18 點(diǎn) 3 分,公元兩千年。時(shí)間的格式可以參考 date 指令,至少需輸入 MMDDHHmm ,就是月日時(shí)與分。 touch -c -t 05061803 file touch -c -t 050618032000 file 將 file 的時(shí)間記錄改變成與 referencefile 一樣。 touch -r referencefile file 將 file 的時(shí)間記錄改成 5 月 6 日 18 點(diǎn) 3 分,公元兩千年。時(shí)間可以使用 am, pm 或是 24 小時(shí)的格式,日期可以使用其他格式如 6 May 2000 。 touch -d "6:03pm" file touch -d "05/06/2000" file touch -d "6:03pm 05/06/2000" file touch 也可以制造一個(gè)空檔(0 byte).例如DHCP Server所需的/etc/dhcpd.leases,dhcpd 必須要有這個(gè)檔案才能運(yùn)作正常.[root@/root]#touch /etc/dhcpd.leases[root@/root]#ls -l /etc/dhcpd.leases-rw-r--r-- 1 root root 0 Jul 3 05:50 /etc/dhcpd.leases 記得上一次重灌前把/etc下的設(shè)定檔tar起來(lái),重灌好之后把原有設(shè)定還原,卻發(fā)現(xiàn)系統(tǒng)檢查設(shè)定檔的時(shí)間有問(wèn)題,這個(gè)時(shí)候用 find /etc -name * -exec touch {}; 就可以把設(shè)定檔的時(shí)間更新到與現(xiàn)在一致了。 |