linux删除目录不弹出y,Linux删除目录文件命令-rm | IT运维网

本文详细介绍了Linux中`rm`命令的使用,特别是`-r`(递归删除)、`-f`(强制删除)和`-v`(详细模式)选项。通过实例展示了如何删除文件和目录,强调了使用`-rf`组合时的安全注意事项,提醒用户谨慎操作以避免数据丢失。

格式:rm [OPTION]… FILE…

-r:递归方式删除目录(含目录下的文件)

-f:强制直接删除不需要用户确认

-v:显示指令的详细执行过程

删除指定文件

[root@localhost tmp]# pwd

/tmp

[root@localhost tmp]# ll /tmp/

total 4

drwxr-xr-x 2 root root 6 Nov 28 2017 rty

drwx------ 3 root root 16 Dec 1 2017 systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2

-rw-r--r-- 1 root root 0 Feb 14 20:33 test1.txt

-rw-r--r-- 1 root root 0 Feb 12 21:00 test.txt

drwxr-xr-x 4 root root 24 Feb 14 20:43 z

[root@localhost tmp]# rm test1.txt

rm: remove regular empty file ‘test1.txt’? y

[root@localhost tmp]# ll /tmp/

total 4

drwxr-xr-x 2 root root 6 Nov 28 2017 rty

drwx------ 3 root root 16 Dec 1 2017 systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2

-rw-r--r-- 1 root root 0 Feb 12 21:00 test.txt

drwxr-xr-x 4 root root 24 Feb 14 20:43 z

[root@localhost tmp]#

-f:强制直接删除不需要用户确认

[root@localhost tmp]# ll /tmp/

total 4

drwxr-xr-x 2 root root 6 Nov 28 2017 rty

drwx------ 3 root root 16 Dec 1 2017 systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2

-rw-r--r-- 1 root root 0 Feb 12 21:00 test.txt

drwxr-xr-x 4 root root 24 Feb 14 20:43 z

[root@localhost tmp]# rm -f test.txt

[root@localhost tmp]# ll /tmp/

total 4

drwxr-xr-x 2 root root 6 Nov 28 2017 rty

drwx------ 3 root root 16 Dec 1 2017 systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2

drwxr-xr-x 4 root root 24 Feb 14 20:43 z

[root@localhost tmp]#

-r:递归方式删除目录(含目录下的文件)

[root@localhost tmp]# tree /tmp/

/tmp/

├── rty

├── systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2

│   └── tmp

└── z

├── poi

│   └── 1

│   └── 2

│   └── 3

│   └── 4

│   └── 5

└── x

└── c

└── v

└── b

14 directories, 1 file

[root@localhost tmp]# rm -r /tmp/z/poi/

rm: descend into directory ‘/tmp/z/poi/’? y

rm: descend into directory ‘/tmp/z/poi/1’? y

rm: descend into directory ‘/tmp/z/poi/1/2’? y

rm: descend into directory ‘/tmp/z/poi/1/2/3’? y

rm: descend into directory ‘/tmp/z/poi/1/2/3/4’? y

rm: remove directory ‘/tmp/z/poi/1/2/3/4/5’? y

rm: remove directory ‘/tmp/z/poi/1/2/3/4’? y

rm: remove directory ‘/tmp/z/poi/1/2/3’? y

rm: remove directory ‘/tmp/z/poi/1/2’? y

rm: remove directory ‘/tmp/z/poi/1’? y

rm: remove directory ‘/tmp/z/poi/’? y

[root@localhost tmp]# tree /tmp/

/tmp/

├── rty

├── systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2

│   └── tmp

└── z

└── x

└── c

└── v

└── b

8 directories, 1 file

-rf:直接删除目录(含目录下的文件)无需用户确认

此方式有很大的安全隐患,操作务必谨慎!!!

[root@localhost tmp]# tree /tmp/

/tmp/

├── rty

├── systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2

│   └── tmp

└── z

└── x

└── c

└── v

└── b

8 directories, 1 file

[root@localhost tmp]# rm -rf /tmp/z/

[root@localhost tmp]# tree /tmp/

/tmp/

├── rty

└── systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2

└── tmp

3 directories, 1 file

[root@localhost tmp]#

-v:显示指令的详细执行过程

[root@localhost tmp]# rm -fv test*.txt

removed 'test10.txt'

removed 'test1.txt'

removed 'test2.txt'

removed 'test3.txt'

removed 'test4.txt'

removed 'test5.txt'

removed 'test6.txt'

removed 'test7.txt'

removed 'test8.txt'

removed 'test9.txt'

Ubuntu系统请配合sudo使用(sudo rm)

IT运维网 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Linux删除目录文件命令-rm!

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值