首页·终端命令

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