首頁  >  文章  >  運維  >  Linux指令rmdir的用法總結

Linux指令rmdir的用法總結

巴扎黑
巴扎黑原創
2017-09-04 14:15:273562瀏覽

指令簡介:

此指令用來刪除空目錄,如果目錄非空,則會發生錯誤。可以使用rm刪除目錄中的檔案後,使用rmdir刪除目錄。也可以使用rm -rf取代rmdir指令。這是一個非常簡單的指令。

 

指令語法:

rmdir [OPTION]... DIRECTORY...

 

指令參數:

參數

長參數

描敘

--ignore-fail-on-non-empty

忽略任何應目錄裡面有數據文件而造成的錯誤

-p

--parents

遞迴刪除目錄

-v

--verbose

顯示命令執行的詳細資訊

--help

顯示命令在線幫助

#--version

顯示命令版本資訊

 

使用範例:

1: 查看rmdir指令的說明資訊

[root@testServ ~]# 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 a78933fb2a4ec664f95b7539a7317bf7.

也可以使用下方指令查看rmdir文件資訊

[root@testServ ~]# man rmdir

 

#2: 使用rmdir刪除空目錄

如果目錄非空,則會出現錯誤訊息。

[root@testServ ~]# ls /root/kerry/
file1
[root@testServ ~]# rmdir kerry
rmdir: kerry: Directory not empty
[root@testServ ~]# rm -f /root/kerry/*
[root@testServ ~]# rmdir kerry

 

3:顯示指令執行時的詳細資訊

[root@testServ ~]# mkdir test1  test2 test3
[root@testServ ~]# ls
anaconda-ks.cfg  Desktop  install.log  install.log.syslog  test1  test2  test3
[root@testServ ~]# rmdir -v test1  test2 test3
rmdir: removing directory, test1
rmdir: removing directory, test2
rmdir: removing directory, test3

 

4:遞迴刪除目錄,如下所示,先建立目錄kerry,在kerry目錄下建立空白目錄tmp,接下來空白目錄test

 
[root@testServ ~]# mkdir -p kerry/tmp/test
[root@testServ ~]# tree kerry
kerry
`-- tmp
    `-- test

2 directories, 0 files

[root@testServ ~]# rmdir -p kerry/tmp/test

 

5:忽略任何應目錄裡面有資料檔案而造成的錯誤

[root@testServ ~]# mkdir kerry
[root@testServ ~]# cd kerry
[root@testServ kerry]# touch file1
[root@testServ kerry]# cd ..
[root@testServ ~]# rmdir --ignore-fail-on-non-empty kerry/

以上是Linux指令rmdir的用法總結的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn