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