rm 8.25 命令詳解


rm 可用於移除不需要的 (取消鏈接) 目錄和文件。

rm 可移除一個目錄中的一個或多個文件或目錄,也可移除某個目錄及其下的所有文件及子目錄。

對於鏈接文件,隻是斷開瞭鏈接,源文件保持不變。

另請參閱: mkdir     mv     shred     touch

基本用法     詳細用法

rm ./filename
			

基本語法

rm [OPTION]... FILE...
			

rm 命令默認不會移除目錄;使用 -r 或 -R 或 --recursive 選項纔能移除目錄及其下的所有文件及目錄。

若要移除 -foo 文件,命令形式為 rm -- -foo 或 rm ./-foo。

 

注意


使用 rm 移除文件,若有足夠的專業知識 and/or 時間,還可能恢復其 "全部或部分" 內容。

為確保文件內容真正無法恢復,請考慮使用 shred

Options 選項

參數 EN 解釋 中文翻譯 備注
-f, --force ignore nonexistent files and arguments, never prompt 忽略不存在的文件和自變量,從不提示
-i prompt before every removal 每次移除前提示
-I

prompt once before removing more than three files, or when removing recursively;

less intrusive than -i, while still giving protection against most mistakes

在移除 3 個以上文件之前或遞歸移除時提示一次;

比 -i 更少侵擾,仍可防止大多數失誤

--interactive[=WHEN]

prompt according to WHEN: never, once (-I), or always (-i);

without WHEN, prompt always

提示根據 WHEN:從不、一次 (-I)、總是 (-i);

沒有 WHEN,總是提示

--one-file-system

when removing a hierarchy recursively,

skip any directory

(that is on a file system different from that of the corresponding command line argument)

在遞歸移除層次結構時,

跳過任何目錄

(不同於相應命令行自變量的文件係統)

--no-preserve-root do not treat '/' specially 不特彆對待 '/'
--preserve-root do not remove '/' (default) 不移除 '/' (默認)
-r, -R, --recursive remove directories and their contents recursively 遞歸移除目錄及其內容
-d, --dir remove empty directories 移除空目錄
-v, --verbose explain what is being done 說明正在做什麼
--help display this help and exit 顯示幫助並退齣
--version output version information and exit 輸齣版本信息並退齣

基本用法

功能 命令 文字解釋 示例 示例解釋
文件 rm full-filename 移除 full-filename 完整路徑文件名,指定文件
rm ./filename 移除 filename 相對路徑文件名,指定文件
目錄 rm -d empty-directory 移除 empty-directory 指定空目錄
rm -dir empty-directory 移除 empty-directory 指定空目錄
遞歸 rm -R directory 移除 directory 指定目錄下的所有文件及目錄 rm -r /etc/apt/sources.list.d/ 遞歸移除 /etc/apt/sources.list.d/ 目錄下的所有文件及目錄
rm -R ./filename* 移除 filename* 相對路徑文件名指定的所有文件
幫助 rm --help 展示幫助信息
版本 rm --version 展示版本信息

 

版權聲明: 本文為獨傢原創稿件,版權歸 樂數軟件 ,未經許可不得轉載。