linux的rm命令-删除文件或目录

英文原意:remove

命令所在路径:/bin/rm

语法:rm -r 文件或目录,为目录时要加-r,且删除需要用户确认,如果不需要用户确认则

语法为:rm -r -f

功能:删除文件

例子:删除/test/testfile1文件

[root@localhost test]# rm /test/testfile1

rm: remove regular empty file `/test/testfile1'? y

最后面的?后面的y表示yes即确认删除,输入y后按回车键即删除成功

例子:删除一个多级目录,由于是目录,要加-r否则删除不成功

[root@localhost test]# rm /test/test1

rm: cannot remove `/test/test1': Is a directory

例子:删除一个多级目录,由于目录下有目录,则每一级删除的时候都需要用户确认

[root@localhost test]# rm -r /test/test1

rm: descend into directory `/test/test1'? y

rm: descend into directory `/test/test1/test'? y

rm: remove regular empty file `/test/test1/test/testfile1'? y

rm: remove directory `/test/test1/test/test1'? y

rm: remove directory `/test/test1/test'? y

rm: remove regular empty file `/test/test1/testfile'? y

rm: remove directory `/test/test1'? y

[root@localhost test]#

例子:删除一个多级目录,且不需要用户确定是否删除,加-f达到效果,表示不需要用户确认

[root@localhost test]# rm -r -f /test/test2

-r -f也可以这样合并到一起写:

[root@localhost test]# mkdir /test/test1

[root@localhost test]# mkdir /test/test1/test1

[root@localhost test]# rm -rf /test/test1

[root@localhost test]#

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐