共计 2778 个字符,预计需要花费 7 分钟才能阅读完成。
提醒:本文最后更新于2019-08-02 18:03,文中所关联的信息可能已发生改变,请知悉!
[v_act]格式:rm [OPTION]… FILE…
-r:递归方式删除目录(含目录下的文件)
-f:强制直接删除不需要用户确认
-v:显示指令的详细执行过程
[/v_act]
删除指定文件
[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]#
-f:强制直接删除不需要用户确认
[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]#
-r:递归方式删除目录(含目录下的文件)
[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
-rf:直接删除目录(含目录下的文件)无需用户确认
[v_error]此方式有很大的安全隐患,操作务必谨慎!!![/v_error]
[v_error]此方式有很大的安全隐患,操作务必谨慎!!![/v_error]
[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]#
-v:显示指令的详细执行过程
[root@localhost tmp]# rm -fv test*.txt
removed 'test10.txt'
removed 'test1.txt'
removed 'test2.txt'
removed 'test3.txt'
removed 'test4.txt'
removed 'test5.txt'
removed 'test6.txt'
removed 'test7.txt'
removed 'test8.txt'
removed 'test9.txt'
[v_error]Ubuntu系统请配合sudo使用(sudo rm)[/v_error]
正文完