指令簡介:
該指令用用來删除空目錄,如果目錄非空,則會出現錯誤。可以使用rm删除目錄中的檔案後,使用rmdir删除目錄。也可以使用rm -rf替代rmdir指令。這是一個非常簡單的指令。
指令文法:
rmdir [OPTION]... DIRECTORY...
指令參數:
參數 | 長參數 | 描叙 |
--ignore-fail-on-non-empty | 忽略任何應目錄裡面有資料檔案而造成的錯誤 | |
-p | --parents | 遞歸删除目錄 |
-v | --verbose | 顯示指令執行的詳細資訊 |
使用示例:
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 <[email protected]>.
也可以使用下面指令檢視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