欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Linux命令每天必學(xué)(5)之rm命令

 更新時(shí)間:2016年01月20日 10:50:42   作者:peida  
rm是常用的命令,該命令的功能為刪除一個(gè)目錄中的一個(gè)或多個(gè)文件或目錄,它也可以將某個(gè)目錄及其下的所有文件及子目錄均刪除。對(duì)于鏈接文件,只是刪除了鏈接,原有文件均保持不變

昨天學(xué)習(xí)了創(chuàng)建文件和目錄的命令mkdir ,今天學(xué)習(xí)一下linux中刪除文件和目錄的命令: rm命令。rm是常用的命令,該命令的功能為刪除一個(gè)目錄中的一個(gè)或多個(gè)文件或目錄,它也可以將某個(gè)目錄及其下的所有文件及子目錄均刪除。對(duì)于鏈接文件,只是刪除了鏈接,原有文件均保持不變。

rm是一個(gè)危險(xiǎn)的命令,使用的時(shí)候要特別當(dāng)心,尤其對(duì)于新手,否則整個(gè)系統(tǒng)就會(huì)毀在這個(gè)命令(比如在/(根目錄)下執(zhí)行rm * -rf)。所以,我們?cè)趫?zhí)行rm之前最好先確認(rèn)一下在哪個(gè)目錄,到底要?jiǎng)h除什么東西,操作時(shí)保持高度清醒的頭腦。

1.命令格式:

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

2.命令功能:

刪除一個(gè)目錄中的一個(gè)或多個(gè)文件或目錄,如果沒有使用- r選項(xiàng),則rm不會(huì)刪除目錄。如果使用 rm 來刪除文件,通常仍可以將該文件恢復(fù)原狀。

3.命令參數(shù):

-f, --force 忽略不存在的文件,從不給出提示。
-i, --interactive 進(jìn)行交互式刪除
-r, -R, --recursive 指示rm將參數(shù)中列出的全部目錄和子目錄均遞歸地刪除。
-v, --verbose 詳細(xì)顯示進(jìn)行的步驟
--help 顯示此幫助信息并退出
--version 輸出版本信息并退出

4.命令實(shí)例:

實(shí)例一:刪除文件file,系統(tǒng)會(huì)先詢問是否刪除。

命令:

rm 文件名

輸出:

復(fù)制代碼 代碼如下:

[root@localhost test1]# ll

總計(jì) 4

復(fù)制代碼 代碼如下:

-rw-r--r-- 1 root root 56 10-26 14:31 log.log
root@localhost test1]# rm log.log

rm:是否刪除 一般文件 “l(fā)og.log”? y

復(fù)制代碼 代碼如下:

root@localhost test1]# ll

總計(jì) 0[root@localhost test1]#

說明:

輸入rm log.log命令后,系統(tǒng)會(huì)詢問是否刪除,輸入y后就會(huì)刪除文件,不想刪除則數(shù)據(jù)n。

實(shí)例二:強(qiáng)行刪除file,系統(tǒng)不再提示。

命令:

復(fù)制代碼 代碼如下:

rm -f log1.log

輸出:

復(fù)制代碼 代碼如下:

[root@localhost test1]# ll

總計(jì) 4

復(fù)制代碼 代碼如下:

-rw-r--r-- 1 root root 23 10-26 14:40 log1.log
[root@localhost test1]# rm -f log1.log
[root@localhost test1]# ll

總計(jì) 0[root@localhost test1]#

實(shí)例三:刪除任何.log文件;刪除前逐一詢問確認(rèn)

命令:

rm -i *.log

輸出:

復(fù)制代碼 代碼如下:

[root@localhost test1]# ll

總計(jì) 8

復(fù)制代碼 代碼如下:

-rw-r--r-- 1 root root 11 10-26 14:45 log1.log
-rw-r--r-- 1 root root 24 10-26 14:45 log2.log
[root@localhost test1]# rm -i *.log

rm:是否刪除 一般文件 “l(fā)og1.log”? y

rm:是否刪除 一般文件 “l(fā)og2.log”? y

[root@localhost test1]# ll

總計(jì) 0[root@localhost test1]#

實(shí)例四:將 test1子目錄及子目錄中所有檔案刪除

命令:

復(fù)制代碼 代碼如下:

rm -r test1

輸出:

復(fù)制代碼 代碼如下:

[root@localhost test]# ll

總計(jì) 24drwxr-xr-x 7 root root 4096 10-25 18:07 scf

復(fù)制代碼 代碼如下:

drwxr-xr-x 2 root root 4096 10-26 14:51 test1
drwxr-xr-x 3 root root 4096 10-25 17:44 test2
drwxrwxrwx 2 root root 4096 10-25 17:46 test3
drwxr-xr-x 2 root root 4096 10-25 17:56 test4
drwxr-xr-x 3 root root 4096 10-25 17:56 test5
[root@localhost test]# rm -r test1

rm:是否進(jìn)入目錄 “test1”? y

rm:是否刪除 一般文件 “test1/log3.log”? y

rm:是否刪除 目錄 “test1”? y

復(fù)制代碼 代碼如下:

[root@localhost test]# ll

總計(jì) 20drwxr-xr-x 7 root root 4096 10-25 18:07 scf

復(fù)制代碼 代碼如下:

drwxr-xr-x 3 root root 4096 10-25 17:44 test2
drwxrwxrwx 2 root root 4096 10-25 17:46 test3
drwxr-xr-x 2 root root 4096 10-25 17:56 test4
drwxr-xr-x 3 root root 4096 10-25 17:56 test5
[root@localhost test]#

實(shí)例五:rm -rf test2命令會(huì)將 test2 子目錄及子目錄中所有檔案刪除,并且不用一一確認(rèn)

命令:

復(fù)制代碼 代碼如下:

rm -rf test2

輸出:

復(fù)制代碼 代碼如下:

[root@localhost test]# rm -rf test2
[root@localhost test]# ll

總計(jì) 16drwxr-xr-x 7 root root 4096 10-25 18:07 scf

復(fù)制代碼 代碼如下:

drwxrwxrwx 2 root root 4096 10-25 17:46 test3
drwxr-xr-x 2 root root 4096 10-25 17:56 test4
drwxr-xr-x 3 root root 4096 10-25 17:56 test5
[root@localhost test]#

實(shí)例六:刪除以 -f 開頭的文件

命令:

rm -- -f

輸出:

復(fù)制代碼 代碼如下:

[root@localhost test]# touch -- -f
[root@localhost test]# ls -- -f
-f[root@localhost test]# rm -- -f

rm:是否刪除 一般空文件 “-f”? y

復(fù)制代碼 代碼如下:

[root@localhost test]# ls -- -f

ls: -f: 沒有那個(gè)文件或目錄

復(fù)制代碼 代碼如下:

[root@localhost test]#

也可以使用下面的操作步驟:

復(fù)制代碼 代碼如下:

[root@localhost test]# touch ./-f
[root@localhost test]# ls ./-f
./-f[root@localhost test]# rm ./-f

rm:是否刪除 一般空文件 “./-f”? y

復(fù)制代碼 代碼如下:

[root@localhost test]#

實(shí)例七:自定義回收站功能

命令:

復(fù)制代碼 代碼如下:

myrm(){ D=/tmp/$(date +%Y%m%d%H%M%S); mkdir -p $D; mv "$@" $D && echo "moved to $D ok"; }

輸出:

復(fù)制代碼 代碼如下:

[root@localhost test]# myrm(){ D=/tmp/$(date +%Y%m%d%H%M%S); mkdir -p $D; mv "$@" $D && echo "moved to $D ok"; }
[root@localhost test]# alias rm='myrm'
[root@localhost test]# touch .log .log .log
[root@localhost test]# ll
總計(jì)
-rw-r--r-- root root - : .log
-rw-r--r-- root root - : .log
-rw-r--r-- root root - : .log
drwxr-xr-x root root - : scf
drwxrwxrwx root root - : test
drwxr-xr-x root root - : test
drwxr-xr-x root root - : test
[root@localhost test]# rm [].log
moved to /tmp/ ok
[root@localhost test]# ll
總計(jì) drwxr-xr-x root root - : scf
drwxrwxrwx root root - : test
drwxr-xr-x root root - : test
drwxr-xr-x root root - : test
[root@localhost test]# ls /tmp//
.log .log .log
[root@localhost test]#

說明:

上面的操作過程模擬了回收站的效果,即刪除文件的時(shí)候只是把文件放到一個(gè)臨時(shí)目錄中,這樣在需要的時(shí)候還可以恢復(fù)過來。

下面再給大家詳細(xì)介紹下名稱:rm命令

使用權(quán)限:任何使用者

使用方式:rm [options] name...

說明:刪除檔案及目錄。

參數(shù):

-i 刪除前逐一詢問確認(rèn)。
-f 即使原檔案屬性設(shè)為唯讀,亦直接刪除,無需逐一確認(rèn)。
-r 將目錄及以下之檔案亦逐一刪除。

范例:

刪除任何C語言程式檔;刪除前逐一詢問確認(rèn) :

rm -i *.c

將 Finished 子目錄及子目錄中任何檔案刪除 :

rm -r Finished

功能說明:刪除文檔或目錄。

語  法:rm [-dfirv][--help][--version][文檔或目錄...]

補(bǔ)充說明:執(zhí)行rm指令可刪除文檔或目錄,如欲刪除目錄必須加上參數(shù)"-r",否則預(yù)設(shè)僅會(huì)刪除文檔。

參  數(shù):

 -d或--directory  直接把欲刪除的目錄的硬連接數(shù)據(jù)刪成0,刪除該目錄。

 -f或--force  強(qiáng)制刪除文檔或目錄。

 -i或--interactive  刪除既有文檔或目錄之前先詢問用戶。

 -r或-R或--recursive  遞歸處理,將指定目錄下的任何文檔及子目錄一并處理。

 -v或--verbose  顯示指令執(zhí)行過程。

 --help  在線幫助。

 --version  顯示版本信息

相關(guān)文章

最新評(píng)論