1

From the standard Windows command line (cmd.exe), one can use the command cd\ to jump to the root of the current drive (cd followed by a backslash, with no space between).

With PowerShell, we have the ability to define string aliases for cmdlets, but the command cd\ works just fine from the standard cmd.exe and is therefore not a PowerShell alias.

Is this simply a built-in shortcut to the more standard use of the cd command where you specify the target directory as a parameter to the command itself (with a space between the command and the parameter as expected)?

  • 1
    cd\ works just like dir\ or anycommand\ because the tokens will be split before `\` due to it being an invalid character in filenames – phuclv Jan 3 '18 at 1:46
  • Thank you @LưuVĩnhPhúc for the concise response, this helps greatly. – Ladranas Jan 3 '18 at 2:15
  • I cover this in my answer to Jonas Köritz's earlier question about why "cd.." works without a space. I don't fully agree with LưuVĩnhPhúc's comment because a backslash can be part of a subdirectory's relative path. In short, this behavior has to do with the fact that the "cd" command is special because that command is recognized as an "internal" command that is built into the command line interpreter/shell. – TOOGAM Jun 30 '18 at 20:19
0

With PowerShell, we have the ability to define string aliases for cmdlets, but the command cd\ works just fine from the standard cmd.exe and is therefore not a PowerShell alias.

Just because it's a standard form in CMD doesn't mean it's not an alias in PS. In fact, nearly ever "standard command" in CMD that also works in PS is an alias. CD is an alias for set-location.

Use the command get-alias cd to learn this and other startling tricks!

WHY CD\ is a valid command is not a question SuperUser can answer.

UPDATE

CMD doesn't need to load PS to do anything.

Reading your comments I'm getting the idea that the first thing you need to recognize is that CD\ behaved this way in CMD long before PS came along, so forget PS. To get PS mixed up in this is to bring confusion. Have you forgotten PS yet? (The correct answer here is "yes") Good.

As Lưu Vĩnh Phúc mentions in his comment, command strings can be escaped using various methods and for various reasons. WHY they do this is up to the individual command parser, the host system, the specific command, the people or teams or organizations that developed all these, and possibly other reasons too.

  • I understand that Powershell aliases exist for so-called "standard commands" and that you can list the aliases in the way described, though I was more curious as to how the standard command prompt (cmd.exe) interprets and parses the command "cd\" when you haven't loaded PowerShell to begin with (ie, this is not a case of starting cmd.exe and then typing powershell to jump into a PS prompt). – Ladranas Jan 3 '18 at 1:40
  • Some things in CMD.EXE is just plain idiosyncrasies. – Hannu Jan 3 '18 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.