Linux touch命令使用方法詳解

來源:互聯網
上載者:User


Linux touch命令使用方法詳解 命令名稱:touch 使用許可權:所有使用者 使用方式:  www.2cto.com  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 列出版本訊息。 範例: 最簡單的使用方式,將檔案的時候記錄改為現在的時間。若檔案不存在,系統會建立一個新的檔案。   www.2cto.com  touch file touch file1 file2將 file 的時間記錄改為 5 月 6 日 18 點 3 分,公元兩千年。時間的格式可以參考 date 指令,至少需輸入 MMDDHHmm ,就是月日時與分。touch -c -t 05061803 file touch -c -t 050618032000 file將 file 的時間記錄改變成與 referencefile 一樣。 touch -r referencefile file將 file 的時間記錄改成 5 月 6 日 18 點 3 分,公元兩千年。時間可以使用 am, pm 或是 24 小時的格式,日期可以使用其他格式如 6 May 2000 。 
 touch -d "6:03pm" file touch -d "05/06/2000" file touch -d "6:03pm 05/06/2000" filetouch 也可以製造一個空檔(0 byte).例如DHCP Server所需的/etc/dhcpd.leases,dhcpd 必須要有這個檔案才能運作正常.[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下的設定檔tar起來,重灌好之後把原有設定還原,卻發現系統檢查設定檔的時間有問題,這個時候用 find /etc -name * -exec touch {};就可以把設定檔的時間更新到與現在一致了。  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.