zoukankan      html  css  js  c++  java
  • 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、没发现创建的这样的目录或文件有什么应用场景,了解即可

  • 相关阅读:
    Java基础(六)
    Java基础(五)
    Java基础(四)
    Java基础(三)
    Java变量,标识符,数据类,运算符,表达式,Scanner(二)
    Mybatis(二) SQL映射文件
    Mybatis(一) 入门
    Ubuntu 16.04安装docker详细步骤
    Ubuntu原生源
    运用 jenkins 让你的项目优雅的持续化集成
  • 原文地址:https://www.cnblogs.com/chenjinxi/p/7550024.html
Copyright © 2011-2022 走看看