深入解析Linux 常用命令--rm

深入解析Linux常用命令–rm

1.概述

rm也是我们经常用到的一个Linux命令,常用于文件和文件夹的删除,rm取自于remove。官方解释为:“Remove files or directories”,即移除文件和目录。

2.各选项解释

1)-f

-f选项表示:不管文件是否存在均不出现提示。

[root@smart linux]# rm -f a.t
[root@smart linux]# rm -f b.t

2)-r/-R

-r/-R表示:递归删除文件或目录

[root@smart linux]# rm -r a
rm: remove regular file `a'? y
[root@smart linux]# rm -r g
rm: descend into directory `g'? y
rm: remove directory `g/abcde'? y
rm: remove directory `g'? y
[root@smart linux]# rm -R e
rm: descend into directory `e'? y
rm: remove regular file `e/b.c'? y
rm: remove directory `e'? y
[root@smart linux]# ls
A      a.txt  B    b.c~   c  f  kl.txt  rm.txt  s.txt
abcde  b      b.c  b.txt  d  h  k.txt   ss      test
[root@smart linux]# 

3)-i

-i表示:在删除文件前,提示确认信息。一般情况下,Linux都对这个命令重定义为这个选项。即默认情况下删除文件都会存在提示。

[root@smart linux]# rm -i a.t
rm: cannot remove `a.t': No such file or directory
[root@smart linux]# rm a.t
rm: cannot remove `a.t': No such file or directory
[root@smart linux]# 

4)-v

-v表示:执行后显示正在进行的动作,同其他命令。

[root@smart linux]# rm -v a.txt b.txt
rm: cannot remove `a.txt': No such file or directory
rm: cannot remove `b.txt': No such file or directory
[root@smart linux]# rm -v k.txt
rm: remove regular file `k.txt'? y
removed `k.txt'
[root@smart linux]# rm -fv s.txt
removed `s.txt'
[root@smart linux]# 

5)–preserve-root

–preserve-root表示:保护根目录(/)路径。此选项可以避免误操作删除根目录,导致整个系统崩溃的风险,推荐使用。

[root@smart linux]# rm --preserve-root /
rm: cannot remove `/': Is a directory
[root@smart linux]# rm --preserve-root / b
rm: cannot remove `/': Is a directory
rm: remove regular file `b'? y
[root@smart linux]# ls
A  abcde  B  b.c  b.c~  c  d  f  h  kl.txt  rm.txt  ss  test
[root@smart linux]# ls /
bin   cgroup  etc   lib         media  mnt  opt   root  selinux  sys  usr
boot  dev     home  lost+found  misc   net  proc  sbin  srv      tmp  var

Enjoy!


2017/12/24

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值