Linux命令集(Linux文件管理命令–rm指令篇)

Linux命令集(Linux文件管理命令–rm指令篇)希望能够帮助正在 Linux 路上奋斗的你

大家好,欢迎来到IT知识分享网。

Linux文件管理命令集(rm指令篇)


如下为笔者总结出在linux中最常用的rm指令集
🌟希望能够帮助正在Linux路上奋斗的你🌟


3. rm(remove)

删除文件或目录

rm filename.py #删除文件filename.py 
rm -r [directory] #删除文件目录[directory]及其内容 
短选项 长选项 描述
-f --force 忽略不存在的文件,不给出提示
-i --interactive 进行交互式删除操作,删除前逐一询问确认
-r --recursive 将指定目录及其子目录递归删除
-v --verbose 显示指令执行过程
-I --ignore-missing 忽略不存在的文件和参数错误
-R --recursive,--r 将指定目录及其子目录递归删除,删除时不提示
-- --help 显示帮助信息
-- --version 显示版本信息

下述为rm命令详细选项(–help)

Usage: rm [OPTION]... [FILE]... Remove (unlink) the FILE(s). -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 --interactive[=WHEN] prompt according to WHEN: never, once (-I), or always (-i); without WHEN, prompt always --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 By default, rm does not remove directories. Use the --recursive (-r or -R) option to remove each listed directory, too, along with all of its contents. To remove a file whose name starts with a '-', for example '-foo', use one of these commands: rm -- -foo rm ./-foo Note that if you use rm to remove a file, it might be possible to recover some of its contents, given sufficient expertise and/or time. For greater assurance that the contents are truly unrecoverable, consider using shred. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/rm> or available locally via: info '(coreutils) rm invocation' * * 使用方法:rm [选项]... [文件]... 删除(unlink)FILE(S)。 -f, --force 忽略不存在的文件和参数,不要提示 -i 在每次删除之前提示 -I 在删除超过三个文件或递归删除时提示一次。比-i less intrusive,并且仍然对大多数错误提供保护。 --interactive[=WHEN] 根据 WHEN 提示:never、once (-I) 或 always (-i)。如果没有 WHEN,就始终提示。 --one-file-system 递归删除层次结构时,跳过任何与相应命令行参数所在的文件系统不同的目录。 --no-preserve-root 不将'/'视为特殊情况。 --preserve-root 不删除'/'(默认) -r, -R, --recursive 递归删除目录及其内容 -d, --dir 删除空目录 -v, --verbose 解释正在进行的操作 --help 显示此帮助信息并退出 --version 输出版本信息并退出 默认情况下,rm 不会删除目录。 使用 --recursive(-r 或 -R)选项来连同所有内容一起删除每个列出的目录。 要删除名称以 '-' 开头的文件,例如 '-foo',请使用以下命令之一: rm -- -foo rm ./-foo 请注意,如果使用 rm 删除文件,则可能会恢复其中的某些内容,如果具备足够的专业知识和/或时间。 为了更好地保证内容无法恢复,请考虑使用 shred。 GNU 核心实用程序在线帮助:http://www.gnu.org/software/coreutils/ 完整的文档见:http://www.gnu.org/software/coreutils/rm 或者在本地使用 info '(coreutils) rm invocation' 查看。 

1. 删除文件

删除单个或多个文件

rm file1.txt file2.txt 

2. 强制删除文件

即使文件属性为只读也可以直接删除,无需确认

rm -f file.txt 

3. 提示确认,删除前需逐一询问是否确认删除

rm -i file.txt 

4. 递归删除目录下的文件和目录

文件名重合会覆盖目标文件而不提示

rm -r directory/ 

5. 不提示确认,直接删除目录下的所有内容

rm -rf directory/ 

6. 在执行删除之前显示警告信息,如“要删除文件吗?”

当文件名重合时不覆盖目标文件

rm -w file.txt 

7. 显示删除进度

rm -v file.txt 

8. 删除隐藏文件或目录

rm -r .directory/ 

9. 不删除文件夹下的子目录

rm -d directory/* 

10. 在删除前进行预览,并列出将要执行删除操作的文件列表

rm -l file.txt 


免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/118575.html

(0)
上一篇 2025-11-12 09:26
下一篇 2025-11-12 09:45

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信