国产宅男网站在线|亚洲A级性爱免费视频|亚洲中精品级在线|午夜福利AA毛

  • <dd id="gf5jf"><th id="gf5jf"></th></dd>

    <cite id="gf5jf"><label id="gf5jf"></label></cite>
  • <div id="gf5jf"><listing id="gf5jf"></listing></div>
    學(xué)習(xí)啦>學(xué)習(xí)電腦>操作系統(tǒng)>Linux教程>

    Linux命令rm文件和目錄管理詳解

    時(shí)間: 志藝942 分享

      rm 命令可以刪除一個(gè)目錄中的一個(gè)或多個(gè)文件或目錄,也可以將某個(gè)目錄及其下屬的所有文件及其子目錄均刪除掉。對(duì)于鏈接文件,只是刪除整個(gè)鏈接文件,而原有文件保持不變。接下來是小編為大家收集的Linux 命令 rm文件和目錄管理詳解,歡迎大家閱讀:

      Linux 命令 rm文件和目錄管理詳解

      命令名稱

      rm

      命令全稱

      Remove

      基本語法

      rm [選項(xiàng)]… 文件…

      功能描述

      刪除文件或目錄

      命令選項(xiàng)

      注意:如果使用 rm 來刪除文件,通常仍可以將該文件恢復(fù)原狀。如果想保證該文件的內(nèi)容無法還原,請(qǐng)考慮使用 shred。

      使用范例

      1.不帶任何選項(xiàng),運(yùn)行 rm

      這是 rm 命令最基礎(chǔ)的使用,將文件直接刪除。

      [wang@localhost test]$ ll

      總用量 0

      -rw-rw-r--. 1 wang wang 0 10月 20 10:11 test.txt

      [wang@localhost test]$ rm test.txt

      [wang@localhost test]$ ll

      總用量 0

      [wang@localhost test]$

      2.同時(shí)刪除多個(gè)文件

      要同時(shí)刪除多個(gè)文件,只需要將多個(gè)文件用空格隔開。

      [wang@localhost test]$ ll

      總用量 0

      -rw-rw-r--. 1 wang wang 0 10月 20 10:15 test1.txt

      -rw-rw-r--. 1 wang wang 0 10月 20 10:15 test2.txt

      [wang@localhost test]$ rm test1.txt test2.txt

      [wang@localhost test]$ ll

      總用量 0

      [wang@localhost test]$

      3.強(qiáng)行刪除

      使用 -f 選項(xiàng)會(huì)強(qiáng)制進(jìn)行刪除操作。如果目標(biāo)文件不能打開,可以用 -f 嘗試。

      [wang@localhost test]$ ll

      總用量 0

      -rw-rw-r--. 1 wang wang 0 10月 20 10:37 test.txt

      [wang@localhost test]$ rm -f test.txt

      [wang@localhost test]$ ll

      總用量 0

      [wang@localhost test]$

      4.顯示詳細(xì)的進(jìn)行步驟

      默認(rèn)情況下,當(dāng)刪除成功時(shí),僅會(huì)再次看到命令提示符。如果想了解在刪除文件時(shí)都發(fā)生了什么,可以用 -v 選項(xiàng)。

      [wang@localhost test]$ rm -v test.txt test1.txt

      已刪除"test.txt"

      已刪除"test1.txt"

      5.使用交互模式

      使用 -i 選項(xiàng),啟用交互模式,會(huì)詢問是否繼續(xù)刪除。

      [wang@localhost test]$ rm -i test.txt test1.txt

      rm:是否刪除普通空文件 "test.txt"?y

      rm:是否刪除普通空文件 "test1.txt"?n

      [wang@localhost test]$ ll

      總用量 0

      -rw-rw-r--. 1 wang wang 0 10月 20 10:24 test1.txt

      如果確認(rèn)刪除,輸入 y(yes);如果不想刪除,輸入 n(no)。

      6.遞歸刪除目錄及其內(nèi)容

      要?jiǎng)h除一個(gè)目錄,需要添加 -r 或者 -R 選項(xiàng)來遞歸實(shí)現(xiàn)。

      [wang@localhost test]$ tree dir

      dir

      ├── subDir

      │ ├── test1.txt

      │ └── test.txt

      ├── test1.txt

      └── test.txt

      1 directory, 4 files

      # 不帶選項(xiàng) -r 或者 -R,則無法刪除

      [wang@localhost test]$ rm dir

      rm: 無法刪除"dir": 是一個(gè)目錄

      [wang@localhost test]$ rm -r dir

      [wang@localhost test]$ ls

      [wang@localhost test]$

      7.刪除鏈接文件

      對(duì)于鏈接文件,只是刪除整個(gè)鏈接文件,而原有文件保持不變。

      [wang@localhost doc]$ ll debug_link.log

      lrwxrwxrwx. 1 wang wang 27 10月 19 15:59 debug_link.log -> /home/wang/script/debug.log

      [wang@localhost doc]$ rm debug_link.log

      [wang@localhost doc]$ ll /home/wang/script/debug.log

      -rw-rw-r--. 1 wang wang 368640 10月 19 15:58 /home/wang/script/debug.log

      8.刪除以“-”開頭的文件

      要?jiǎng)h除以“-”開頭的文件(例如:-foo),請(qǐng)使用以下方法之一:

      rm -- -foo

      rm ./-foo

      使用方式如下:

      [wang@localhost test]$ touch -- -foo

      [wang@localhost test]$ ll

      總用量 0

      -rw-rw-r--. 1 wang wang 0 10月 20 10:45 -foo

      [wang@localhost test]$ rm -- -foo

      [wang@localhost test]$ ll

      總用量 0

      [wang@localhost test]$

      或者:

      [wang@localhost test]$ touch ./-foo

      [wang@localhost test]$ ll

      總用量 0

      -rw-rw-r--. 1 wang wang 0 10月 20 10:47 -foo

      [wang@localhost test]$ rm ./-foo

      [wang@localhost test]$ ll

      總用量 0

      [wang@localhost test]$

      為什么非要這么用呢?假如使用 rm -foo :

      [wang@localhost test]$ touch ./-foo

      [wang@localhost test]$ rm -foo

      rm:無效選項(xiàng) -- o

      Try 'rm ./-foo' to remove the file "-foo".

      Try 'rm --help' for more information.

      這是因?yàn)橐话?ldquo;-”后面接的是選項(xiàng)。因此,單純地使用 rm -foo,系統(tǒng)的命令就會(huì)誤判。所以,只能用避過首字符“-”的方式(加上本目錄 ./)。

      
    看了“Linux 命令 rm文件和目錄管理詳解”還想看:
    1.linux rm刪除文件和目錄使用詳解

    2.Linux rm命令怎么使用

    3.Linux中的文件與目錄mv命令使用解析

    4.Linux指令檔案目錄管理mv介紹

    5.Linux中rm與rmdir刪除命令的用法詳解

    6.Linux命令rmdir和rm有什么不同

    2962069