← 返回列表

Linux shell rmdir 命令

Linux shell rmdir 命令删除空的目录。 rmdir 命令语法 rmdir [-p] dirName 参数 -p 是当子目录被删除后使它也成为空目录的话,则顺便一并删除 范例 将工作目录下,名为 aaa 的子目录删除 : [root@localhost ~]# ls aaa abc anaconda-ks.cfg bbb shell testfile testfile_1 [root@localhost ~]# rmdir aaa [root@localhost ~]# ls abc anaconda-ks.cfg bbb shell testfile testfile_1 在工作目录下的 bbb 目录中,删除名为 test 的子目录。若 test 删除后,bbb 目录成为空目录,则 bbb 亦予删除。 [root@localhost ~]# tree . . ├── abc ├── anaconda-ks.cfg ├── bbb │ └── test ├── shell │ ├── demo1.sh │ ├── demo2.sh │ ├── demo.cpp │ ├── demo.sh │ ├── main.c │ └── w.sh ├── testfile └── testfile_1 4 directories, 9 files [root@localhost ~]# rmdir -p bbb/test [root@localhost ~]# tree . . ├── abc ├── anaconda-ks.cfg ├── shell │ ├── demo1.sh │ ├── demo2.sh │ ├── demo.cpp │ ├── demo.sh │ ├── main.c │ └── w.sh ├── testfile └── testfile_1 2 directories, 9 files [root@localhost ~]# 返回上一级

Linux shell rmdir 命令删除空的目录。

rmdir 命令语法

rmdir [-p] dirName

参数

-p 是当子目录被删除后使它也成为空目录的话,则顺便一并删除

范例

将工作目录下,名为 aaa 的子目录删除 :

[root@localhost ~]# ls
aaa  abc  anaconda-ks.cfg  bbb  shell  testfile  testfile_1
[root@localhost ~]# rmdir aaa
[root@localhost ~]# ls
abc  anaconda-ks.cfg  bbb  shell  testfile  testfile_1

在工作目录下的 bbb 目录中,删除名为 test 的子目录。若 test 删除后,bbb 目录成为空目录,则 bbb 亦予删除。

[root@localhost ~]# tree .
.
├── abc
├── anaconda-ks.cfg
├── bbb
│   └── test
├── shell
│   ├── demo1.sh
│   ├── demo2.sh
│   ├── demo.cpp
│   ├── demo.sh
│   ├── main.c
│   └── w.sh
├── testfile
└── testfile_1

4 directories, 9 files
[root@localhost ~]# rmdir -p bbb/test
[root@localhost ~]# tree .
.
├── abc
├── anaconda-ks.cfg
├── shell
│   ├── demo1.sh
│   ├── demo2.sh
│   ├── demo.cpp
│   ├── demo.sh
│   ├── main.c
│   └── w.sh
├── testfile
└── testfile_1

2 directories, 9 files
[root@localhost ~]#

返回上一级

打开资源 ↗

交流与评论