bash中的特殊文件夹
2016-03-15 12:20
459 查看
今天整理磁盘的时候发现一个文件夹叫做‘-help'
尝试进去看看里边有什么东西,却发现怎么也进不去
对于其他的特殊字符,通常单引号就可以搞定了
那'-help'到底要怎么进呢。 在这里不得不再次吐槽一下百度,怎样都查不到想要的结果,“cd 减号开头 目录” “cd -开头目录” “cd 特殊字符目录” 全部查不到! 查!不!到!
只好google,一查必中,都不用全部输入,输入'cd -' 相关推荐就是我想要的东西了。
下边是正确答案了,如果你看我啰嗦到这里,我相信,是真爱,哈哈哈。
答案来自 ServerFault,两种方法,其中“--” 这个选项,又是我所不知道的,要学的东西太多,加油!
Use the
As a commenter noted, this convention is also defined in the POSIX standard:
Default Behavior: When this section is listed as "None.", it means that the implementation need not support any options. Standard utilities that do not accept options, but that do accept operands, shall recognize
The requirement for recognizing
and avoid any problems with -m used as an extension.
as well as:
Guideline 10:
The argument
Specify the path explicitly:
$ ls -F -help/
尝试进去看看里边有什么东西,却发现怎么也进不去
$ cd -help bash: cd: -h: invalid option cd: usage: cd [-L|-P] [dir] $ cd '-help' bash: cd: -h: invalid option cd: usage: cd [-L|-P] [dir] $ cd "\-help" bash: cd: \-help: No such file or directory
对于其他的特殊字符,通常单引号就可以搞定了
$ ls -F help/ #help/ -help/ \help/ $ cd #help $ pwd ~ $ cd - cd /tmp $ cd '#help' $ pwd /tmp/#help $ cd .. $ cd ' help' $ pwd /tmp/ help $ cd .. $ cd '\help' $ pwd /tmp/\help
那'-help'到底要怎么进呢。 在这里不得不再次吐槽一下百度,怎样都查不到想要的结果,“cd 减号开头 目录” “cd -开头目录” “cd 特殊字符目录” 全部查不到! 查!不!到!
只好google,一查必中,都不用全部输入,输入'cd -' 相关推荐就是我想要的东西了。
下边是正确答案了,如果你看我啰嗦到这里,我相信,是真爱,哈哈哈。
答案来自 ServerFault,两种方法,其中“--” 这个选项,又是我所不知道的,要学的东西太多,加油!
Use the
--argument.
cd -- -2This uses a convention common to GNU tools which is to not treat anything that appears after
--as a command line option.
As a commenter noted, this convention is also defined in the POSIX standard:
Default Behavior: When this section is listed as "None.", it means that the implementation need not support any options. Standard utilities that do not accept options, but that do accept operands, shall recognize
"--"as a first argument to be discarded.
The requirement for recognizing
"--"is because conforming applications need a way to shield their operands from any arbitrary options that the implementation may provide as an extension. For example, if the standard utility foo is listed as taking no options, and the application needed to give it a pathname with a leading hyphen, it could safely do it as:
foo -- -myfile
and avoid any problems with -m used as an extension.
as well as:
Guideline 10:
The argument
--should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the
'-'character. The
--argument should not be used as an option or as an operand.
Specify the path explicitly:
cd ./-2This specifies the path explicitly naming the current directory (
.) as the starting point.
cd $(pwd)/-2 cd /absolute/path/to/-2These are variations on the above. Any number of such variations may be possible; I'll leave it as an exercise to the reader to discover all of them.
相关文章推荐
- LeetCode:Shell题目
- linux下提示bash:command not found
- Linux学习3之shell的if大小比对使用
- shell脚本实现nginx开机自启
- linux之shell学习:sort使用
- shell脚本--判断输入的ip是否正确
- 如何使用PowerShell管理Windows服务
- shell命令行处理getops/getopt
- shell 之 cat 显示不可见字符
- shell 之 echo
- 【shell】参数默认值
- 【shell变量替换】
- 73条日常Linux shell命令汇总
- Linux学习笔记——Bash常用快捷键
- 使用xshell使用删除出现乱码
- 使用xshell使用删除出现乱码
- 73条日常Linux shell命令汇总
- shell与aw的简单交互示例
- PowerShell复制目录以及目录下文件
- shell中的数学计算:正式和浮点数的计算