Linux基础命令[7]-rm

1. rm 命令说明

rm 用于删除文件或目录,删除后无法找回,基本信息如下:

Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).

  -f, --force           ignore nonexistent files, 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
  -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 is usually possible to recover
the contents of that file.  If you want more assurance that the contents are
truly unrecoverable, consider using shred.

Report rm bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'rm invocation'

参数如下:

选项作用
-f强制删除,没有提示
-i每次删除前都会提示
-r递归地删除目录及其内容
-v列出详细信息

在这里插入图片描述

2. rm 命令语法

mv [选项] 文件/目录

3. rm 命令示例

3.1 直接删除(不加参数)

rm 文件名

不加参数时,若文件存在,则直接删除;若不存在,则报错提示。

在这里插入图片描述

3.2 -f(强制删除)

-f 这个参数很多命令都有,一般都是 force 的意思。

rm -f 文件名

在这里插入图片描述

3.3 -i(删除提示)

同样的,很多的命令都有 -i,一般就是提示的意思,y 执行,n 不执行

rm -i 文件名

在这里插入图片描述

3.4 -r(删除目录)

当需要删除整个目录时,必须加 -r ,该目录下的所有内容,包括文件和子目录都会被删除。

rm -r 目录名

在这里插入图片描述

3.5 -v(展示信息)

同样,-v 也是很多命令都有的,它会将命令执行结果展示出来。还有一些参数也是共同的,例如 --help(命令帮助,将命令的信息列出),–version(展示命令的版本信息)

rm -v 文件名

在这里插入图片描述

4. 总结

rm 删除文件或目录,不可找回,所以使用此命令时,一定要谨慎。删除时,一定要确定好目标文件或目录,如果把

rm -rf ./*

输入成了

rm -rf /*

就可以跑路了。

在这里插入图片描述
在这里插入图片描述
(图网,侵删)

  • 14
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值