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]#

 

 

man rm 的說明

 

man getopts 的說明

 

小結:

  1、-- 就相當於 轉義字符斜杠 \ 的效果

  2、沒發現創建的這樣的目錄或文件有什么應用場景,了解即可

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM