5

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

Kenster
  • 23,465
  • 21
  • 80
  • 106
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363

1 Answers1

7

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.

ddavison
  • 28,221
  • 15
  • 85
  • 110
  • Ah ok I don't remember downloading anything for `ls`. How can I do the same for `cd`? – CodyBugstein Jun 03 '16 at 18:13
  • Can you help me figure out what `ls` program I have? – CodyBugstein Jun 03 '16 at 18:14
  • well, i'd recommend consolidating your environment. since you are trying to use unix commands, use [Cygwin](https://www.cygwin.com/). don't mix and match different executables between linux and windows. i.e., don't use command prompt if you intend to use unix commands :) – ddavison Jun 03 '16 at 18:14
  • `where ls` in almost all command prompts reveals where your executable lies – Kimmax Jun 03 '16 at 18:23
  • So how do I actually navigate to `.ssh`? I am not sure where the actual directory lives – CodyBugstein Jun 03 '16 at 18:24
  • 2
    `cd %USERPROFILE%\.ssh` should do the trick, assuming that you're using cmd and the .ssh folder lives under your userprofile – Kimmax Jun 03 '16 at 18:25