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

CodyBugstein picture CodyBugstein · Jun 3, 2016 · Viewed 8.5k times · Source

If the ls command lists the contents of a directory, then some output to ls <directory would seem to indicate that a directory exists.

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

Answer

ddavison picture ddavison · Jun 3, 2016

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.

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

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.