touch

ファイルとディレクトリ

書き方

touch [file]

ファイルの時刻を今にし、無ければ空で作ります。中身は決して触りません。

よく使うオプション

オプション意味
-aChange only the access time
-mChange only the modification time
-cDo not create the file if it is missing
-rCopy the timestamps from another file
-tSet an explicit time as [[CC]YY]MMDDhhmm[.SS]
-dGNU: set the time from a phrase such as -d yesterday

touch notes.md

Creates it empty, or just bumps the time.

touch -t 202401011200 report.pdf

Sets the time to noon on 1 Jan 2024.

touch -r a.txt b.txt

Gives b.txt the same times as a.txt.

移したり消したり探したりするものです。聞き返してくれない命令が混ざっているので、-i を付ける癖が手を守ります。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. touch は何をしますか。

ファイルの時刻を今にし、無ければ空で作ります。中身は決して触りません。

Q. どう打ちますか。

touch [file] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man touch にあります。このコマンドはファイルとディレクトリの仲間です。

関連するコマンド

man ページ: man touch