格式:rm [OPTION]… FILE…
* H5 E9 m+ ~: e3 ?" Z- A6 \' d -r:递归方式删除目录(含目录下的文件)# \1 L7 c( H1 y6 y
-f:强制直接删除不需要用户确认$ D8 Z) P B% k, w, o. }
删除指定文件$ c7 ~4 f9 r& S6 w
- [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#
3 I: v+ ^7 A1 b7 @, r ! t+ l6 F) H. N' v
-f:强制直接删除不需要用户确认% E+ [! D% v! \) ^9 r4 W+ V
- [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# ; E% l7 @3 i% f) k3 E
3 k9 J0 ^- V3 A( [; F4 j& d-r:递归方式删除目录(含目录下的文件)
+ I! E& p) n8 o4 T4 t% w7 \- [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
' G5 K, X& [9 M+ j9 D' n* v( ?
直接删除目录(含目录下的文件)无需用户确认& F, a* J; Z" p! n6 t
此方式有很大的安全隐患,操作务必谨慎!!!0 ?# t, U4 i$ C9 {0 O h9 ~
& O' S% |9 Q1 `' x# G1 Q
- [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# ( T) B' V4 Y/ `, o: i
' J$ o+ o3 f0 |; c x' x5 v0 }
' q8 `* ?' [3 S; T2 W& j5 y0 C9 C
|