linux命令之rmdir

1.rmdir介绍

linux命令rmdir(全称:remove directory)用来删除空目录

2.rmdir用法

rmdir [参数] directory

rmdir参数

参数

说明

-p

递归删除空目录(父目录及子目录都必须为空)

-v

详细显示目录删除信息

3.实例

3.1.删除空目录

命令:

rmdir a

[root@centos79-3 ~]# ls -l a
total 0
[root@centos79-3 ~]# rmdir a
[root@centos79-3 ~]# ls -l a
ls: cannot access a: No such file or directory
[root@centos79-3 ~]#

3.2.递归删除空目录

命令:

rmdir -p 1/2/3

[root@centos79-3 ~]# ls -l 1/2/3/
total 0
[root@centos79-3 ~]# rmdir -pv 1/2/3/
rmdir: removing directory, ‘1/2/3/’
rmdir: removing directory, ‘1/2’
rmdir: removing directory, ‘1’
[root@centos79-3 ~]# ls -l 1/2/3/
ls: cannot access 1/2/3/: No such file or directory
[root@centos79-3 ~]#

3.3.删除非空目录

命令:

rm -rf ztj

其中:

-r        -->表示递归

-f        -->表示强制

[root@centos79-3 ~]# tree ztj
ztj
├── 1
│   └── 2.txt
└── aa.txt

1 directory, 2 files
[root@centos79-3 ~]# rmdir -pv ztj
rmdir: removing directory, ‘ztj’
rmdir: failed to remove ‘ztj’: Directory not empty
[root@centos79-3 ~]# rm -rf ztj
[root@centos79-3 ~]# ls -l ztj
ls: cannot access ztj: No such file or directory
[root@centos79-3 ~]#