touch 不僅能創建空文件,更是修改文件訪問時間、修改時間的核心工具。本文系統整理參數含義、時間格式規範、引用文件時間戳及批量操作實例。
touch [選項] 文件...
| 參數 | 功能 |
|---|---|
| -a | 僅修改訪問時間 |
| -m | 僅修改修改時間 |
| -c / --no-create | 文件不存在時不創建 |
| -r file / --file=file | 引用指定文件的時間戳 |
| -d time / --date=time | 設置指定時間(支持多種格式) |
| -t STAMP | 設置時間戳,格式 [[CC]YY]MMDDhhmm[.ss] |
| --time=WORD | 指定時間類型:atime/access/use 或 mtime/modify |
touch -t 050116082011 file(2011年5月1日 16:08)touch -d "2011-05-01 16:08" file touch -d "4:08pm 05/01/2011" file touch -d "16:08" file # 今日指定時間 touch -d "20110501" file # 日期默認 00:00:00
touch -r referencefile targetfiletouch file1 file2touch *touch -r source.txt dest.txttouch -c flagfileatime 和 mtime 為當前時間find 可批量修改:find /path -name "*.log" -exec touch -d "2023-01-01" {} \;