linux系列(六):rmdir命令

一、命令格式:spa

  rmdir [选项] 目录名code

二、命令功能:blog

  该命令从一个目录中删除一个或多个子目录项,删除某目录时也必须具备对父目录的写权限。class

三、命令参数:test

- p 删除指定目录后,若该目录的上层目录已变成空目录,则将其一并删除;

-v, --verbose  显示指令执行过程 

四、经常使用实例:file

(1)、rmdir不能删除非空目录。权限

命令:di

  rmdir test1co

输出:参数

felix@felix-computer:~/test$ tree
.
├── test1
│   ├── hello.txt
│   └── test2
└── test3

3 directories, 1 file
felix@felix-computer:~/test$ rmdir test1
rmdir: 删除 'test1' 失败: 目录非空
felix@felix-computer:~/test$ rmdir test3
felix@felix-computer:~/test$ tree
.
└── test1
    ├── hello.txt
    └── test2

2 directories, 1 file
felix@felix-computer:~/test$

说明:

rmdir 目录名  该命令不能直接删除非空目录

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

命令:

  rmdir -p test3/test/test4/test5

输出:

felix@felix-computer:~/test$ tree
.
├── test1
│   ├── hello.txt
│   ├── test2
│   └── test4
└── test3
    └── test
        └── test4
            └── test5

7 directories, 1 file
felix@felix-computer:~/test$ rmdir -p test3/test/test4/test5
felix@felix-computer:~/test$ tree
.
└── test1
    ├── hello.txt
    ├── test2
    └── test4

3 directories, 1 file
felix@felix-computer:~/test$ 
相关文章
相关标签/搜索