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