有趣的rm -rf

先放一段Bash记录在这里:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
root@enabling-clam:~# mkdir testdir && cd testdir && ls -la
total 0
drwxr-xr-x 1 root root 0 Jul 8 06:35 .
drwx------ 1 root root 52 Jul 8 06:35 ..

root@enabling-clam:~/testdir# mkdir mydir1 && echo "Test1" > myfile1 && echo "Test2" > mydir1/myfile2 && ls -la
total 4
drwxr-xr-x 1 root root 26 Jul 8 06:36 .
drwx------ 1 root root 52 Jul 8 06:35 ..
drwxr-xr-x 1 root root 14 Jul 8 06:36 mydir1
-rw-r--r-- 1 root root 6 Jul 8 06:36 myfile1

root@enabling-clam:~/testdir# echo "foolish rm" > "-rf" && ls -la
total 8
-rw-r--r-- 1 root root 11 Jul 8 06:37 -rf
drwxr-xr-x 1 root root 32 Jul 8 06:37 .
drwx------ 1 root root 52 Jul 8 06:35 ..
drwxr-xr-x 1 root root 14 Jul 8 06:36 mydir1
-rw-r--r-- 1 root root 6 Jul 8 06:36 myfile1

root@enabling-clam:~/testdir# rm * && ls -la
total 4
-rw-r--r-- 1 root root 11 Jul 8 06:37 -rf
drwxr-xr-x 1 root root 6 Jul 8 06:37 .
drwx------ 1 root root 52 Jul 8 06:35 ..

root@enabling-clam:~/testdir# rm -rf && ls -la
total 4
-rw-r--r-- 1 root root 11 Jul 8 06:37 -rf
drwxr-xr-x 1 root root 6 Jul 8 06:37 .
drwx------ 1 root root 52 Jul 8 06:35 ..

root@enabling-clam:~/testdir# rm "-rf" && ls -la
total 4
-rw-r--r-- 1 root root 11 Jul 8 06:37 -rf
drwxr-xr-x 1 root root 6 Jul 8 06:37 .
drwx------ 1 root root 52 Jul 8 06:35 ..

root@enabling-clam:~/testdir# rm "./-rf" && ls -la
total 0
drwxr-xr-x 1 root root 0 Jul 8 06:38 .
drwx------ 1 root root 52 Jul 8 06:35 ..
root@enabling-clam:~/testdir#