rm

ファイルとディレクトリ

書き方

rm -rf [path]

ファイルを完全に消します。ごみ箱は無く、rm -rf に空白が一つ紛れ込むだけで意図しないものが消えます。

よく使うオプション

オプション意味
-rDescend into directories and delete what is inside
-fNever prompt, and say nothing about files that are missing
-iAsk before every single removal
-dRemove an empty directory without -r
-vPrint each name as it goes
-IGNU: ask once before removing more than three files
-PmacOS: overwrite the file before unlinking it

rm -rf build

Deletes the build directory and everything under it.

rm -i *.log

Asks about each log file first.

rm -- -weird

Deletes a file whose name starts with a dash.

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

読み方

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

よくある質問

Q. rm は何をしますか。

ファイルを完全に消します。ごみ箱は無く、rm -rf に空白が一つ紛れ込むだけで意図しないものが消えます。

Q. どう打ちますか。

rm -rf [path] — 角括弧は省いてよい部分です。

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

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

関連するコマンド

man ページ: man rm