linux系列(六):rmdir命令

一、命令格式:spa

  rmdir [選項] 目錄名code

二、命令功能:blog

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

三、命令參數:test

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

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

四、經常使用實例:file

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

命令:di

  rmdir test1co

輸出:參數

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$ 
相關文章
相關標籤/搜索