bash 为什么 ls ~/.ssh 可以工作,但 cd ~/.ssh 不行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37620728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does ls ~/.ssh work but not cd ~/.ssh?
提问by CodyBugstein
If the ls
command lists the contents of a directory, then some output to ls <directory
would seem to indicate that a directory exists.
如果该ls
命令列出目录的内容,则某些输出ls <directory
似乎表明目录存在。
For example, this is what I get:
例如,这就是我得到的:
> ls ~/.ssh
id_rsa id_rsa.pub known_hosts
But why then, when I type cd ~/.ssh
do I get
但为什么呢,当我打字时cd ~/.ssh
,我会得到
> cd ~/.ssh
The system cannot find the path specified.
?
?
Why can I list the contents of this directory but not navigate to it?
为什么我可以列出这个目录的内容但不能导航到它?
I am using Windows 8
我使用的是 Windows 8
回答by ddavison
This answer is under the assumption that you are using the command prompt to execute these commands.
此答案假设您正在使用命令提示符来执行这些命令。
The reason that you can ls
the directory but not cd
to it, is because the ls
command comes from a library that you downloaded that makes ls
work on windows.
您可以ls
访问目录但不能cd
访问它的原因是因为该ls
命令来自您下载的可以ls
在 Windows 上运行的库。
In contrast, your cd
command is being executed from Windows, not from the library you downloaded.
相反,您的cd
命令是从 Windows 执行的,而不是从您下载的库中执行的。
In short, ls
knows how to parse the tilde (~
) as home, but windows doesn't know how to parse ~
. try it: cd ~
. it won't work.
简而言之,ls
知道如何将波浪号 ( ~
)解析为 home,但 windows 不知道如何解析~
. 试试看: cd ~
。它不会工作。