linux系列(六):rmdir命令


1、命令格式:

  rmdir [選項] 目錄名

2、命令功能:

  該命令從一個目錄中刪除一個或多個子目錄項,刪除某目錄時也必須具有對父目錄的寫權限。

3、命令參數:

- p 刪除指定目錄后,若該目錄的上層目錄已變成空目錄,則將其一並刪除;

-v, --verbose  顯示指令執行過程 

4、常用實例:

(1)、rmdir不能刪除非空目錄。

命令:

  rmdir test1

輸出:

felix@felix-computer:~/test$ tree
.
├── test1
│   ├── hello.txt
│   └── test2
└── test3

3 directories, 1 file
felix@felix-computer:~/test$ rmdir test1
rmdir: 刪除 'test1' 失敗: 目錄非空
felix@felix-computer:~/test$ rmdir test3
felix@felix-computer:~/test$ tree
.
└── test1
    ├── hello.txt
    └── test2

2 directories, 1 file
felix@felix-computer:~/test$

說明:

rmdir 目錄名  該命令不能直接刪除非空目錄

(2)、rmdir -p 當子目錄被刪除后使它也成為空目錄的話,則順便一並刪除

命令:

  rmdir -p test3/test/test4/test5

輸出:

felix@felix-computer:~/test$ tree
.
├── test1
│   ├── hello.txt
│   ├── test2
│   └── test4
└── test3
    └── test
        └── test4
            └── test5

7 directories, 1 file
felix@felix-computer:~/test$ rmdir -p test3/test/test4/test5
felix@felix-computer:~/test$ tree
.
└── test1
    ├── hello.txt
    ├── test2
    └── test4

3 directories, 1 file
felix@felix-computer:~/test$ 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM