首页 > 系统相关 >Linux(Centos 7.6)命令详解:rmdir

Linux(Centos 7.6)命令详解:rmdir

时间:2025-01-07 12:34:22浏览次数:22  
标签:Dir3 Dir2 Dir1 Centos 7.6 rmdir test node2 root

1.命令作用

如果目录为空,则删除该目录(Remove the DIRECTORY(ies), if they are empty)

2.命令语法

Usage: rmdir [OPTION]... DIRECTORY...

3.参数详解

OPTION:

  • --ignore-fail-on-non-empty,忽略每个因为目录为非空的错误(如果目录非空,不会报错也不会删除非空目录)
  • -p, --parents,删除目录及其父级目录(上层目录)
  • -v, --verbose,删除目录显示删除信息

4.常用用例

1.--ignore-fail-on-non-empty参数使用

[root@node2 test]# tree
.
├── Dir1
│   └── Dir2
│       └── Dir3
│           └── file1
├── Dir2
└── Dir3

5 directories, 1 file
[root@node2 test]# rmdir Dir1/                             ## 直接删除会提示目录非空
rmdir: failed to remove ‘Dir1/’: Directory not empty
[root@node2 test]# rmdir --ignore-fail-on-non-empty Dir1/  ## 添加参数删除不会提示错误
[root@node2 test]# tree                                    ## 但实际目录没有删除
.
├── Dir1
│   └── Dir2
│       └── Dir3
│           └── file1
├── Dir2
└── Dir3

5 directories, 1 file
[root@node2 test]# 

2.-p参数使用

[root@node2 test]# tree
.
├── Dir1
│   └── Dir2
│       └── Dir3
│           └── file1
├── Dir2
└── Dir3

5 directories, 1 file
[root@node2 test]# rmdir -p Dir1
rmdir: failed to remove ‘Dir1’: Directory not empty
[root@node2 test]# rm -rf Dir1/Dir2/Dir3/file1 
[root@node2 test]# tree
.
├── Dir1
│   └── Dir2
│       └── Dir3
├── Dir2
└── Dir3

5 directories, 0 files
[root@node2 test]# rmdir -p Dir1
rmdir: failed to remove ‘Dir1’: Directory not empty
[root@node2 test]# rmdir -p Dir1/Dir2/Dir3/         ## 目录为空,-p参数可级联删除
[root@node2 test]# tree
.
├── Dir2
└── Dir3

2 directories, 0 files
[root@node2 test]# 

3.-v参数使用

[root@node2 test]# ll
total 0
drwxr-xr-x. 2 root root 6 Jan  6 14:04 Dir2
drwxr-xr-x. 2 root root 6 Jan  6 20:53 Dir3
[root@node2 test]# rmdir -v Dir2/           ## -v参数删除会提示删除信息
rmdir: removing directory, ‘Dir2/’
[root@node2 test]# ll
total 0
drwxr-xr-x. 2 root root 6 Jan  6 20:53 Dir3
[root@node2 test]# 

标签:Dir3,Dir2,Dir1,Centos,7.6,rmdir,test,node2,root
From: https://blog.csdn.net/Querycache/article/details/144972300

相关文章