Linux 如何建立或删除以横杠(-)开头的文件或目录

小测试:测试

 1 [root@test test]# ls
 2 [root@test test]# touch -abc
 3 touch: invalid option -- 'b'
 4 Try `touch --help' for more information.
 5 [root@test test]# touch -m
 6 touch: missing file operand
 7 Try `touch --help' for more information.
 8 [root@test test]# mkdir --hello
 9 mkdir: unrecognized option '--hello'
10 Try `mkdir --help' for more information.
11 [root@test test]# mkdir -world
12 mkdir: invalid option -- 'w'
13 Try `mkdir --help' for more information.
14 [root@test test]# 
15 [root@test test]# ls
16 [root@test test]# 
17 [root@test test]# mkdir -- -world
18 [root@test test]# ls
19 -world
20 [root@test test]# touch -- -abc
21 [root@test test]# ls
22 -abc  -world
23 [root@test test]# rm -f -abc
24 rm: invalid option -- 'a'
25 Try `rm ./-abc' to remove the file `-abc'.
26 Try `rm --help' for more information.
27 [root@test test]# 
28 [root@test test]# rm -fr -world/
29 rm: invalid option -- 'w'
30 Try `rm ./-world/' to remove the file `-world/'.
31 Try `rm --help' for more information.
32 [root@test test]# rm -fr -- -abc
33 [root@test test]# ls
34 -world
35 [root@test test]# rm -fr -- -world/
36 [root@test test]# 
37 [root@test test]# 
38 [root@test test]# mkdir -- -hello
39 [root@test test]# ls
40 -hello
41 [root@test test]# rm -fr *   # 连通配符都搞不定
42 rm: invalid option -- 'h'
43 Try `rm ./-hello' to remove the file `-hello'.
44 Try `rm --help' for more information.

补充:

[root@test test]# rm -fr -- *
[root@test test]# ls
[root@test test]# spa

 

 

man rm 的说明code

 

man getopts 的说明orm

 

小结:blog

  一、-- 就至关于 转义字符斜杠 \ 的效果rem

  二、没发现建立的这样的目录或文件有什么应用场景,了解便可get