1、命令格式:

  rmdir [选项] 目录名

2、命令功能:

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

3、命令参数:

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

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

4、常用实例:

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

命令:

  rmdir test1

输出:

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$ 

 

相关文章:

  • 2022-12-23
  • 2021-06-18
  • 2021-11-29
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
猜你喜欢
  • 2021-06-15
  • 2021-11-21
  • 2021-09-30
  • 2022-02-20
  • 2021-09-05
  • 2021-11-08
  • 2022-01-27
相关资源
相似解决方案