Linux(Centos 7.6)命令详解:rmdir

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]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值