linux一步一脚印---rmdir命令

1 命令功能(简要说明):

    用来删除空目录,如果目录非空,则出现错误,rmdir --> remove directory

2 命令语法:

    rmdir 【选项】 【目录名】     #注:【】中的内容为非必选项

3 命令选项(只做常用命令参数讲述):

  使用帮助命令:man rmdir 或 rmdir --help

   --ignore-fail-on-non-empty 忽略任何因目录里面有数据文件而造成的错误

  -p,--parents 递归删除目录

  -v,--verbose 显示命令执行的详细信息

4 使用范例:

  (1)rmdir  目录名 【,目录名】

#删除当前路径下的目录
[root@localhost command_test]# ls
dir
[root@localhost command_test]# rmdir dir
[root@localhost command_test]# ls
[root@localhost command_test]# 
#删除指定目录,这里指定删除了目录dir2,而dir1还存在
[root@localhost command_test]# ls
dir1
[root@localhost command_test]# cd dir1
[root@localhost dir1]# ls
dir2
[root@localhost dir1]# cd ..
[root@localhost command_test]# ls
dir1
[root@localhost command_test]# rmdir dir1/dir2
[root@localhost command_test]# ls
dir1
[root@localhost command_test]# cd dir1
[root@localhost dir1]# ls
[root@localhost dir1]# 

  (2)rmdir -p 目录名

#递归删除目录,dir1/dir2 都被删除了
[root@localhost command_test]# ls
dir1
[root@localhost command_test]# cd dir1
[root@localhost dir1]# ls
dir2
[root@localhost dir1]# cd ..
[root@localhost command_test]# rmdir -p dir1/dir2
[root@localhost command_test]# ls
[root@localhost command_test]# 

  (3)rmdir --ignore-fail-on-non-empty 目录名 

#dir1目录下存在dir2,故直接删除会报错;但加上参数后虽不报错,但也不能删除非空
[root@localhost command_test]# ls
dir1
[root@localhost command_test]# cd dir1
[root@localhost dir1]# ls
dir2
[root@localhost dir1]# cd ..
[root@localhost command_test]# rmdir dir1
rmdir: 删除 "dir1" 失败: 目录非空
[root@localhost command_test]# rmdir --ignore-fail-on-non-empty dir1
[root@localhost command_test]# ls
dir1
[root@localhost command_test]# 
原文地址:https://www.cnblogs.com/king-of-purple/p/9365408.html