每天一個linux命令(6):rmdir 命令
今天學習一下linux中(zhong)命(ming)令: rmdir命(ming)令。rmdir是(shi)常用的命令,該命令的功(gong)能是刪除空目錄,一個(ge)目錄(lu)(lu)(lu)被刪(shan)除之前必(bi)須是(shi)空的(de)。(注意,rm - r dir命令可代替rmdir,但(dan)是(shi)有很大危險(xian)性。)刪(shan)除某目錄(lu)(lu)(lu)時也必(bi)須具有對父目錄(lu)(lu)(lu)的(de)寫(xie)權限。
1.命令格式:
rmdir [選項]... 目錄...
2.命令功能:
該命(ming)令從一(yi)個(ge)(ge)目錄(lu)中刪(shan)除一(yi)個(ge)(ge)或多個(ge)(ge)子目錄(lu)項,刪除(chu)某目(mu)錄時也必須具有對父目(mu)錄的寫(xie)權(quan)限。
3.命令參數:
- p 遞(di)歸刪(shan)除(chu)(chu)目錄dirname,當(dang)子(zi)目錄刪(shan)除(chu)(chu)后其父目錄為(wei)空(kong)時,也(ye)一同被刪(shan)除(chu)(chu)。如果(guo)整個路(lu)徑被刪(shan)除或者由于某種原因保留(liu)部(bu)分路(lu)徑,則系統(tong)在標(biao)準輸出上(shang)顯示相應的(de)信息。
-v, --verbose 顯(xian)示指(zhi)令(ling)執行過程
4.命令實例:
實例一:rmdir 不能刪除非空目錄(lu)
命令(ling):
rmdir doc
輸出(chu):
[root@localhost scf]# tree
.
|-- bin
|-- doc
| |-- info
| `-- product
|-- lib
|-- logs
| |-- info
| `-- product
`-- service
`-- deploy
|-- info
`-- product
12 directories, 0 files
[root@localhost scf]# rmdir doc
rmdir: doc: 目(mu)錄(lu)非空(kong)
[root@localhost scf]# rmdir doc/info
[root@localhost scf]# rmdir doc/product
[root@localhost scf]# tree
.
|-- bin
|-- doc
|-- lib
|-- logs
| |-- info
| `-- product
`-- service
`-- deploy
|-- info
`-- product
10 directories, 0 files
說(shuo)明:
rmdir 目錄名 命令不(bu)能(neng)直接刪除(chu)非空目錄
實(shi)例2:rmdir -p 當子(zi)目(mu)錄被刪(shan)除后使它也(ye)成為(wei)空目(mu)錄的話,則順(shun)便一并刪(shan)除
命令:
rmdir -p logs
輸出:
[root@localhost scf]# tree
.
|-- bin
|-- doc
|-- lib
|-- logs
| `-- product
`-- service
`-- deploy
|-- info
`-- product
10 directories, 0 files
[root@localhost scf]# rmdir -p logs
rmdir: logs: 目(mu)錄非空(kong)
[root@localhost scf]# tree
.
|-- bin
|-- doc
|-- lib
|-- logs
| `-- product
`-- service
`-- deploy
|-- info
`-- product
9 directories, 0 files
[root@localhost scf]# rmdir -p logs/product
[root@localhost scf]# tree
.
|-- bin
|-- doc
|-- lib
`-- service
`-- deploy
|-- info
`-- product
7 directories, 0 files
關注 熵減黑客 ,一起學習成長
