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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:44:41  来源:igfitidea点击:

Why does ls ~/.ssh work but not cd ~/.ssh?

bashcmdlscd

提问by CodyBugstein

If the lscommand lists the contents of a directory, then some output to ls <directorywould 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 ~/.sshdo 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 lsthe directory but not cdto it, is because the lscommand comes from a library that you downloaded that makes lswork on windows.

您可以ls访问目录但不能cd访问它的原因是因为该ls命令来自您下载的可以ls在 Windows 上运行的库。

In contrast, your cdcommand is being executed from Windows, not from the library you downloaded.

相反,您的cd命令是从 Windows 执行的,而不是从您下载的库中执行的。

In short, lsknows 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 ~。它不会工作。