Linux命令之rm

rm

命令功能:

刪除文件或目錄


語法:

rm [-fir]文件或目錄


參數:

-f :忽略不存在的文件,不會出現警告信息

-i :互動模式,在刪除前會詢問用戶是否操作

-r :遞歸刪除,最常用在目錄的刪除


命令實踐:

[root@yubinghost~]# alias

alias cp='cp -i'

alias l.='ls -d.* --color=tty'

alias ll='ls -l--color=tty'

alias ls='ls--color=tty'

alias mv='mv -i'

alias rm='rm -i'

aliaswhich='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

[root@yubinghost~]# unalias rm    取消系統命令別名

[root@yubinghost~]# alias

alias cp='cp -i'

alias l.='ls -d.* --color=tty'

alias ll='ls -l--color=tty'

alias ls='ls--color=tty'

alias mv='mv -i'

aliaswhich='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

[root@yubinghost~]# touch yubing.txt

[root@yubinghost~]# ll

total 8476

-rw------- 1root root     939 Apr  3 12:38 anaconda-ks.cfg

-rw-r--r-- 1root root 3422452 Apr  8 10:57etc.tar.bz2

-rw-r--r-- 1root root 5172939 Apr  8 10:55 etc.tar.gz

-rw-r--r-- 1root root   23947 Apr  3 12:37 install.log

-rw-r--r-- 1root root    3619 Apr  3 12:37 install.log.syslog

-rw-r--r-- 1root root      18 Apr  5 14:43 o1

-rw-r--r-- 1root root       0 Apr  5 14:36 oldboy.txt

-rw-r--r-- 1root root      18 Apr  5 14:47 test.txt

-rw-r--r-- 1root root       0 Apr 11 14:27 yubing.txt

[root@yubinghost~]# rm yubing.txt       刪除文件

[root@yubinghost~]# ll

total 8476

-rw------- 1root root     939 Apr  3 12:38 anaconda-ks.cfg

-rw-r--r-- 1root root 3422452 Apr  8 10:57etc.tar.bz2

-rw-r--r-- 1root root 5172939 Apr  8 10:55 etc.tar.gz

-rw-r--r-- 1root root   23947 Apr  3 12:37 install.log

-rw-r--r-- 1root root    3619 Apr  3 12:37 install.log.syslog

-rw-r--r-- 1root root      18 Apr  5 14:43 o1

-rw-r--r-- 1root root       0 Apr  5 14:36 oldboy.txt

-rw-r--r-- 1root root      18 Apr  5 14:47 test.txt

[root@yubinghost~]# touch yubing.txt

[root@yubinghost~]# rm -i yubing.txt     -i互動

rm: removeregular empty file `yubing.txt'? y

[root@yubinghost ~]# alias rm='rm -i'   增加命令別名

[root@yubinghost~]# alias

alias cp='cp -i'

alias l.='ls -d.* --color=tty'

alias ll='ls -l--color=tty'

alias ls='ls--color=tty'

alias mv='mv -i'

alias rm='rm -i'

aliaswhich='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

[root@yubinghost~]# touch yubing.txt

[root@yubinghost~]# rm yubing.txt

rm: removeregular empty file `yubing.txt'? n

[root@yubinghost~]# rm -f yubing.txt     -f強制,沒有出現提示

[root@yubinghost~]#

[root@yubinghost~]# mkdir yubing      創建目錄

[root@yubinghost~]# rm yubing        

rm: cannotremove directory `yubing': Is a directory   提示是目錄,無法刪除

[root@yubinghost~]# rm -r yubing       加上-r參數,可以刪除目錄了

rm: remove directory`yubing'? y

[root@yubinghost~]# ll

total 8476

-rw------- 1root root     939 Apr  3 12:38 anaconda-ks.cfg

-rw-r--r-- 1root root 3422452 Apr  8 10:57etc.tar.bz2

-rw-r--r-- 1root root 5172939 Apr  8 10:55 etc.tar.gz

-rw-r--r-- 1root root   23947 Apr  3 12:37 install.log

-rw-r--r-- 1root root    3619 Apr  3 12:37 install.log.syslog

-rw-r--r-- 1root root      18 Apr  5 14:43 o1

-rw-r--r-- 1root root       0 Apr  5 14:36 oldboy.txt

-rw-r--r-- 1root root      18 Apr  5 14:47 test.txt

[root@yubinghost~]# mkdir -p /yu/bing/txt  創建目錄及子目錄

[root@yubinghost~]# rm -rv /yu/bing/txt  

rm: removedirectory `/yu/bing/txt'? y

removeddirectory: `/yu/bing/txt'  過程顯示,直接將目錄及其字母全部刪除了

[root@yubinghost~]# ll

total 8476

-rw------- 1root root     939 Apr  3 12:38 anaconda-ks.cfg

-rw-r--r-- 1root root 3422452 Apr  8 10:57etc.tar.bz2

-rw-r--r-- 1root root 5172939 Apr  8 10:55 etc.tar.gz

-rw-r--r-- 1root root   23947 Apr  3 12:37 install.log

-rw-r--r-- 1root root    3619 Apr  3 12:37 install.log.syslog

-rw-r--r-- 1root root      18 Apr  5 14:43 o1

-rw-r--r-- 1root root       0 Apr  5 14:36 oldboy.txt

-rw-r--r-- 1root root      18 Apr  5 14:47 test.txt

rm: cannot lstat`yuing': No such file or directory  因爲此文件不存在

[root@yubinghost~]# rm -f yubing    

[root@yubinghost~]#            沒有出提示

[root@yubinghost~]# mkdir -p yu/bing

[root@yubinghost~]# mkdir -p yu/bing

[root@yubinghost~]# ls

anaconda-ks.cfg  install.log install.log.syslog  o1  oldboy.txt test.txt  yu

[root@yubinghost~]# rm yu

rm: cannotremove directory `yu': Is a directory         提示是目錄無法刪除

[root@yubinghost~]# rm -rf yu    -r還是刪除了

[root@yubinghost~]# ls

anaconda-ks.cfg  install.log install.log.syslog  o1  oldboy.txt test.txt

[root@yubinghost ~]# mkdir yubing      創建目錄

[root@yubinghost ~]# touch yubing/yubing.txt   在目錄中創建個文件

[root@yubinghost ~]# cd yubing; ll

total 0

-rw-r--r-- 1 root root 0 Apr 11 12:05yubing.txt

[root@yubinghost yubing]# cd

[root@yubinghost ~]# rmdir yubing

rmdir: yubing: Directory not empty  目錄不爲空,無法使用rmdir刪除

[root@yubinghost ~]#

[root@yubinghost ~]# rm -r yubing

rm: descend into directory `yubing'? y

rm: remove regular empty file`yubing/yubing.txt'? y

rm: remove directory `yubing'? y    一步步逐一刪除了



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章