A.<神奇的魔法>
rm的意義是remove,也就是用來殺掉一個檔案的指令。在UNIX中一個被殺掉 的檔案除非是系統恰好有做備份,否則是無法像DOS裡面一樣還能夠救回來 的。所以在做rm動作的時候應該要特別小心。 雖說rm可以砍除檔案與目錄,但預設的rm是不能砍目錄的,必需要加上特別 的選項才行;但對於作symbolic link的目錄,則可直接刪除目錄的連結。
B.<圖書館>
libc.so.6 => /lib/libc.so.6 (0x4001b000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) Version information:
/bin/rm:libc.so.6 (GLIBC_2.1) => /lib/libc.so.6 libc.so.6 (GLIBC_2.0) => /lib/libc.so.6
/lib/libc.so.6:
ld-linux.so.2 (GLIBC_2.1.1) => /lib/ld-linux.so.2 ld-linux.so.2 (GLIBC_2.1) => /lib/ld-linux.so.2 ld-linux.so.2 (GLIBC_2.0) => /lib/ld-linux.so.2
C.<咒語>
rm [選項] file1 file2 file3 ......
可用的選項有:
-d, --directory : 刪除為symbolic link的目錄(只限 super-user)。 -f, --force : 使系統在刪除時,不提出任何警告訊息,即使要刪除的檔案並不存在,也不會有任何反應。
-i--interactive : 在除去檔案之前均會詢問是否真要除去。 -r, -R, --recursive : 遞迴式的刪除,用以刪除子目錄下之檔案及目錄。 -v, --verbose : 報告程式之運作情況。 --help : 顯示rm的用法,然後離開。
--version : 顯示rm的版本資料,然後離開。D.<示範>
root@here /root> mkdir test ←建立test這個目錄
root@here /root> rm -d test ←rm -d並非rmdir
rm: 刪除目錄 `test' 嗎? y
rm: 不能解除 `test' 之連結: Is a directory
root@here /root> ln test -S testS ←建立symbolic link
root@here /root> su userA ←改用userA的身份
userA@here /root> rm -d testS 刪除testS這個捷徑
rm: 不能刪除 `testS': Permission denied
userA@here /root> exit ←還原為root身份
root@here /root> cd test ←進入test目錄
root@here /test> mkdir test_dir 在其中建立test_dir目錄
root@here /test> cd test_dir 再進入test_dir
root@here /test_dir> vi test_file 編輯test_file,則目錄非空
root@here /test_dir> cd ~/ ←返回/root
root@here /root> rm testS ←刪除symbolic link目錄
rm: remove `testS'? y 無論是否非空,皆可刪除
root@here /root> rm -ir test ←以詢問方式刪除test目錄
rm: descend into directory `test'? y 則會進入一層層的子目錄
rm: descend into directory `test/test_dir'? y
rm: remove `test/test_dir/test_file'? y 一一確認是否刪除裡面的檔案
rm: remove directory `test/test_dir'? n
rm: remove directory `test' (might be nonempty)? n
root@here /root> rm -rifv tes ←f與i並存,i會無作用
removing all entries of directory test 將以強制方式刪除test目錄
removing all entries of directory test/test_dir
removing the directory itself: test/test_dir
removing the directory itself: test 且-v會列出所有刪除的動作
E.<私房話>
1.小心不要隨便使用rm -rf,否則有一天你會"欲哭無淚"……
或者,您可以在shell中動點小手腳,讓rm之前,一定要經您的再確認。 例如,加上一個alias rm '/bin/rm -i'
2.如何刪除以"-"起始的file呢?我們可以在rm之後加"-"這個option,表示
其後的參數皆不代表"選項"的意義。
例如,我們如果要刪除"-f"這個檔案,我們可以這樣做: rm -- -f
因為rm這個指令會去呼叫getopt來剖析其後的選項,當getopt看到"-"這個 選項,就會知道其後的所有參數都不代表選項。 或者,也有人想到直接用"rm ./-f"也可以,這是最簡單的方式了。3.rmdir這個指令是用來刪除空目錄,也就是目錄下不得有其他檔案或子目錄
,除非加上"-p"這個選項,便能指定刪除某特定子目錄。例如:rmdir -p /a/b/c,若c為空目錄,則可把目錄c刪除。
F.<問男人.問女人>
rm(1), rmdir(1), ln(1)
rm - remove (unlink) files or directories
系統:Linux
路徑:/usr/bin/
Shared library:-lc.1 => /usr/lib/libc.so.1.9
-ldl.1 => /usr/lib/libdl.so.1.0
主要用途:將一個或多個檔案刪除掉。
語法:/usr/bin/rm [ - ] [ -fir ] filename...
參數說明:
- Treat the following arguments as filenames `-' so that you can specify filenames starting with a minus.
-f 不詢問使用者,就直接將檔案給刪除掉﹔如果出現error,也不
會出現任何錯誤訊息。
-i 詢問使用者是否要刪除。
-r 將以遞迴的方式刪除掉一個目錄以及此目錄底下所有的檔案及目錄。
其他:由於file的權限問題,因此如果一個使用者沒有權限,將不能刪除掉此檔
案或目錄。
注意!!如果執行'rm -rf *',將刪除目前目錄底下所有資料,除非有備份
,否則將造成無法挽回的遺憾。
禁止執行'rm ..'。
範例:
#移除掉檔案a
<
env.txt rm.txt w.txt 回憶.doc
<
<
a env.txt rm.txt w.txt 回憶.doc
<
<
env.txt rm.txt w.txt 回憶.doc
#移除時將詢問你是否要移除
<
<
env.txt rm.txt w.txt 回憶.doc
#以遞迴方式將資料夾d裡面所有的資料以及d本身移除
<
<
aa dd/
<
<
env.txt rm.txt w.txt 回憶.doc
<