命令簡介:
該命令用用來刪除空目錄,如果目錄非空,則會出現錯誤。可以使用rm刪除目錄中的文件后,使用rmdir刪除目錄。也可以使用rm -rf替代rmdir命令。這是一個非常簡單的命令。
命令語法:
rmdir [OPTION]... DIRECTORY...
命令參數:
參數 |
長參數 |
描敘 |
--ignore-fail-on-non-empty |
忽略任何應目錄里面有數據文件而造成的錯誤 |
|
-p |
--parents |
遞歸刪除目錄 |
-v |
--verbose |
顯示命令執行的詳細信息 |
--help |
顯示命令在線幫助 |
|
--version |
顯示命令版本信息 |
使用示例:
1: 查看rmdir命令的幫助信息
[root@DB-Server ~]# rmdir --help
Usage: rmdir [OPTION]... DIRECTORY...
Remove the DIRECTORY(ies), if they are empty.
--ignore-fail-on-non-empty
ignore each failure that is solely because a directory
is non-empty
-p, --parents Remove DIRECTORY and its ancestors. E.g., `rmdir -p a/b/c' is
similar to `rmdir a/b/c a/b a'.
-v, --verbose output a diagnostic for every directory processed
--help display this help and exit
--version output version information and exit
Report bugs to <bug-coreutils@gnu.org>.
也可以使用下面命令查看rmdir文檔信息
[root@DB-Server ~]# man rmdir
2: 使用rmdir刪除空目錄
如果目錄非空,則會出現錯誤信息。
[root@DB-Server ~]# ls /root/kerry/
file1
[root@DB-Server ~]# rmdir kerry
rmdir: kerry: Directory not empty
[root@DB-Server ~]# rm -f /root/kerry/*
[root@DB-Server ~]# rmdir kerry
3:顯示命令執行時的詳細信息
[root@DB-Server ~]# mkdir test1 test2 test3
[root@DB-Server ~]# ls
anaconda-ks.cfg Desktop install.log install.log.syslog test1 test2 test3
[root@DB-Server ~]# rmdir -v test1 test2 test3
rmdir: removing directory, test1
rmdir: removing directory, test2
rmdir: removing directory, test3
4:遞歸刪除目錄,如下所示,首先創建目錄kerry,在kerry目錄下創建空目錄tmp,接下來空目錄test
[root@DB-Server ~]# mkdir -p kerry/tmp/test
[root@DB-Server ~]# tree kerry
kerry
`-- tmp
`-- test
2 directories, 0 files
[root@DB-Server ~]# rmdir -p kerry/tmp/test
5:忽略任何應目錄里面有數據文件而造成的錯誤
[root@DB-Server ~]# mkdir kerry
[root@DB-Server ~]# cd kerry
[root@DB-Server kerry]# touch file1
[root@DB-Server kerry]# cd ..
[root@DB-Server ~]# rmdir --ignore-fail-on-non-empty kerry/