格式:rm [OPTION]… FILE…5 X( `5 x- }$ H* W E6 r/ |1 w
-r:递归方式删除目录(含目录下的文件)
* @9 o; S$ B7 D -f:强制直接删除不需要用户确认8 ~! N- I1 P0 R. N
删除指定文件
h: A8 P3 ]1 @- [root@localhost tmp# pwd
- /tmp
- [root@localhost tmp# ll /tmp/
- total 4
- drwxr-xr-x 2 root root 6 Nov 28 2017 rty
- drwx------ 3 root root 16 Dec 1 2017 systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2
- -rw-r--r-- 1 root root 0 Feb 14 20:33 test1.txt
- -rw-r--r-- 1 root root 0 Feb 12 21:00 test.txt
- drwxr-xr-x 4 root root 24 Feb 14 20:43 z
- [root@localhost tmp# rm test1.txt
- rm: remove regular empty file ‘test1.txt’? y
- [root@localhost tmp# ll /tmp/
- total 4
- drwxr-xr-x 2 root root 6 Nov 28 2017 rty
- drwx------ 3 root root 16 Dec 1 2017 systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2
- -rw-r--r-- 1 root root 0 Feb 12 21:00 test.txt
- drwxr-xr-x 4 root root 24 Feb 14 20:43 z
- [root@localhost tmp#
+ S8 b, [) e; g4 {
: @" Z% b) ~" H( v- T7 b-f:强制直接删除不需要用户确认
6 N/ ?( Z2 {* l1 ?: Y9 {$ H- [root@localhost tmp# ll /tmp/
- total 4
- drwxr-xr-x 2 root root 6 Nov 28 2017 rty
- drwx------ 3 root root 16 Dec 1 2017 systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2
- -rw-r--r-- 1 root root 0 Feb 12 21:00 test.txt
- drwxr-xr-x 4 root root 24 Feb 14 20:43 z
- [root@localhost tmp# rm -f test.txt
- [root@localhost tmp# ll /tmp/
- total 4
- drwxr-xr-x 2 root root 6 Nov 28 2017 rty
- drwx------ 3 root root 16 Dec 1 2017 systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2
- drwxr-xr-x 4 root root 24 Feb 14 20:43 z
- [root@localhost tmp#
4 }3 R* a# h. `8 \' l! x
+ |- c( g' R$ Z6 c6 Z& W-r:递归方式删除目录(含目录下的文件)& x6 @; ?, Q& v2 p2 C" B
- [root@localhost tmp# tree /tmp/
- /tmp/
- ├── rty
- ├── systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2
- │ └── tmp
- └── z
- ├── poi
- │ └── 1
- │ └── 2
- │ └── 3
- │ └── 4
- │ └── 5
- └── x
- └── c
- └── v
- └── b
-
- 14 directories, 1 file
- [root@localhost tmp# rm -r /tmp/z/poi/
- rm: descend into directory ‘/tmp/z/poi/’? y
- rm: descend into directory ‘/tmp/z/poi/1’? y
- rm: descend into directory ‘/tmp/z/poi/1/2’? y
- rm: descend into directory ‘/tmp/z/poi/1/2/3’? y
- rm: descend into directory ‘/tmp/z/poi/1/2/3/4’? y
- rm: remove directory ‘/tmp/z/poi/1/2/3/4/5’? y
- rm: remove directory ‘/tmp/z/poi/1/2/3/4’? y
- rm: remove directory ‘/tmp/z/poi/1/2/3’? y
- rm: remove directory ‘/tmp/z/poi/1/2’? y
- rm: remove directory ‘/tmp/z/poi/1’? y
- rm: remove directory ‘/tmp/z/poi/’? y
- [root@localhost tmp# tree /tmp/
- /tmp/
- ├── rty
- ├── systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2
- │ └── tmp
- └── z
- └── x
- └── c
- └── v
- └── b
-
- 8 directories, 1 file$ t u9 T/ j8 s( d2 j4 U
直接删除目录(含目录下的文件)无需用户确认
5 J3 T4 R7 Q. c" f# O0 a' N, t 此方式有很大的安全隐患,操作务必谨慎!!!0 r f* l9 B$ {3 ]. Z" _9 o1 L
; B! M+ G* w7 W- [root@localhost tmp# tree /tmp/
- /tmp/
- ├── rty
- ├── systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2
- │ └── tmp
- └── z
- └── x
- └── c
- └── v
- └── b
-
- 8 directories, 1 file
- [root@localhost tmp# rm -rf /tmp/z/
- [root@localhost tmp# tree /tmp/
- /tmp/
- ├── rty
- └── systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2
- └── tmp
-
- 3 directories, 1 file
- [root@localhost tmp#
9 m% a2 z1 Z; W4 F0 q! c0 `! z0 b % o8 \" Y2 {' E' \5 ^5 H$ B: V
8 C7 \2 @ S6 e- X8 P, `
|