rmdir
删除一個空目錄,可以同時删除途經的父目錄,但是要確定父目錄中沒有其他内容。
此指令的适用範圍:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。
1、文法
rmdir [選項] dir
2、選項清單
--version
顯示指令版本資訊
--help
顯示幫助文檔
--ignore-fail-on-non-empty
忽略由非空目錄造成的錯誤資訊
-p | --parent
删除目錄,以及途經的父目錄
-v | --verbose
顯示詳細資訊
3、執行個體
1)簡單删除一個目錄
[root@localhost weijie]# ls -l test //檢視目錄的詳細資訊
總用量 4
drwxr-xr-x 2 root root 4096 9月 10 21:21 test
[root@localhost weijie]# rmdir testt/test/ //删除目錄中的一個子目錄
[root@localhost weijie]# ls -l test //檢視目錄資訊
總用量 0
2)使用-p選項,删除子目錄以及途經的父目錄,父目錄隻有目前的一個子目錄
[root@localhost weijie]# mkdir test02/test //在test02中建立目錄test
You have new mail in /var/spool/mail/root
[root@localhost weijie]# ls test02/ //檢視是否建立成功
test
[root@localhost weijie]# rmdir -p test02/test/ //使用-p選項删除目錄test,這樣會導緻test02一起被删除
[root@localhost weijie]# ls //檢視目前目錄,test02已經不在了
1.c link link1 link2 my.iso test testt wj234.q1C wjtpflR
3)使用-p選項,删除子目錄以及途經的父目錄,父目錄中還有其他内容
[root@localhost weijie]# ls testt/ //檢視目錄内容
1.c test
[root@localhost weijie]# rmdir -p testt/test/ //使用-p選項删除
rmdir: 删除目錄 "testt" 失敗: 目錄非空 //删除途經的父目錄testt出錯,因為這個目錄下還有其他内容
[root@localhost weijie]# ls testt/ //檢視,子目錄已經删除
1.c
4)同時改變所有者群組
[root@localhost weijie]# ls -l 1.c //目前的組是weijie
-rwxr--r-- 1 root weijie 0 9月 7 09:11 1.c
[root@localhost weijie]# chown 500:500 1.c //把組和所有者都改為500,注意文法,中間有個冒号
[root@localhost weijie]# ls -l 1.c
-rwxr--r-- 1 david david 0 9月 7 09:11 1.c
做了一個Linux學習的平台,目前出來一個雛形,各位可以參考使用
連結:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ 密碼:n7bk
