rm
ファイルとディレクトリ
書き方
rm -rf [path]ファイルを完全に消します。ごみ箱は無く、rm -rf に空白が一つ紛れ込むだけで意図しないものが消えます。
よく使うオプション
| オプション | 意味 |
|---|---|
| -r | Descend into directories and delete what is inside |
| -f | Never prompt, and say nothing about files that are missing |
| -i | Ask before every single removal |
| -d | Remove an empty directory without -r |
| -v | Print each name as it goes |
| -I | GNU: ask once before removing more than three files |
| -P | macOS: overwrite the file before unlinking it |
例
rm -rf buildDeletes the build directory and everything under it.
rm -i *.logAsks about each log file first.
rm -- -weirdDeletes 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