Ubuntu rm 命令详解


rm 可用于移除不需要的 (取消链接) 目录和文件。

rm 可移除一个目录中的一个或多个文件或目录,也可移除某个目录及其下的所有文件及子目录。

对于链接文件,只是断开了链接,源文件保持不变。

另请参阅: mkdir     shred     touch

基本用法     详细用法

rm ./filename
			

基本语法

rm [OPTION]... FILE...
			

rm 命令默认不会移除目录;使用 -r 或 -R 或 --recursive 选项才能移除目录及其下的所有文件及目录。

若要移除 -foo 文件,命令形式为 rm -- -foo 或 rm ./-foo。

 

注意


使用 rm 移除文件,若有足够的专业知识 and/or 时间,还可能恢复其 "全部或部分" 内容。

为确保文件内容真正无法恢复,请考虑使用 shred

Options 选项

参数 EN 解释 中文翻译 备注
-f, --force ignore nonexistent files and arguments, never prompt 忽略不存在的文件和自变量,从不提示
-i prompt before every removal 每次移除前提示
-I

prompt once before removing more than three files, or when removing recursively;

less intrusive than -i, while still giving protection against most mistakes

在移除 3 个以上文件之前或递归移除时提示一次;

比 -i 更少侵扰,仍可防止大多数失误

--interactive[=WHEN]

prompt according to WHEN: never, once (-I), or always (-i);

without WHEN, prompt always

提示根据 WHEN:从不、一次 (-I)、总是 (-i);

没有 WHEN,总是提示

--one-file-system

when removing a hierarchy recursively,

skip any directory

(that is on a file system different from that of the corresponding command line argument)

在递归移除层次结构时,

跳过任何目录

(不同于相应命令行自变量的文件系统)

--no-preserve-root do not treat '/' specially 不特别对待 '/'
--preserve-root do not remove '/' (default) 不移除 '/' (默认)
-r, -R, --recursive remove directories and their contents recursively 递归移除目录及其内容
-d, --dir remove empty directories 移除空目录
-v, --verbose explain what is being done 说明正在做什么
--help display this help and exit 显示帮助并退出
--version output version information and exit 输出版本信息并退出

基本用法

功能 命令 文字解释 示例 示例解释
文件 rm full-filename 移除 full-filename 完整路径文件名,指定文件
rm ./filename 移除 filename 相对路径文件名,指定文件
目录 rm -d empty-directory 移除 empty-directory 指定空目录
rm -dir empty-directory 移除 empty-directory 指定空目录
递归 rm -R directory 移除 directory 指定目录下的所有文件及目录 rm -r /etc/apt/sources.list.d/ 递归移除 /etc/apt/sources.list.d/ 目录下的所有文件及目录
rm -R ./filename* 移除 filename* 相对路径文件名指定的所有文件
帮助 rm --help 展示帮助信息
版本 rm --version 展示版本信息

 

版权声明: 本文为独家原创稿件,版权归 乐数软件 ,未经许可不得转载。