touch
檔案與目錄
用法
touch [file]把檔案時間改成現在,檔案不存在就建一個空的;內容一個位元組都不動。
常用選項
| 選項 | 含義 |
|---|---|
| -a | Change only the access time |
| -m | Change only the modification time |
| -c | Do not create the file if it is missing |
| -r | Copy the timestamps from another file |
| -t | Set an explicit time as [[CC]YY]MMDDhhmm[.SS] |
| -d | GNU: set the time from a phrase such as -d yesterday |
範例
touch notes.mdCreates it empty, or just bumps the time.
touch -t 202401011200 report.pdfSets the time to noon on 1 Jan 2024.
touch -r a.txt b.txtGives b.txt the same times as a.txt.
搬移、刪除和尋找。有些命令不會再問一次,所以順手加 -i 是在救自己。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. touch 是做什麼的?
把檔案時間改成現在,檔案不存在就建一個空的;內容一個位元組都不動。
Q. 怎麼寫?
touch [file] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 6 個,完整列表在 man touch。這條命令屬於檔案與目錄。
相關命令
man 手冊: man touch