2

I already know what it does: It simply goes one directory or folder backwards.

But what's mysterious for me are those two dot.

cd.. #it has the same function as popd with the difference that it changes the 
     #current working directory

If someone tell me what is the philosophy of putting those two Dots, i would really appreciate it.

U. Windl
  • 3,480
  • 26
  • 54
moh80s
  • 763
  • 1
  • 7
  • 21
  • 1
    Please read the Microsoft article about [Naming Files, Paths, and Namespaces](https://learn.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). It explains everything you need to know about Windows file systems, absolute and relative paths, etc. – Mofi Oct 05 '19 at 09:29
  • 2
    The comment after `cd..` is nonsense. `popd` changes also the current directory. `popd` changes the current directory to directory which was the current directory before execution of corresponding `pushd`. – Mofi Oct 05 '19 at 09:33
  • 1
    The command line `cd..` is syntactically not correct. The correct command line would be `cd ..` with a space between the command `cd` (argument 0) and its first and only parameter `..` (argument 1). – Mofi Oct 05 '19 at 09:34
  • 1
    @Mofi: `cd..` is syntactically correct in both `cmd.exe` and PowerShell, it's just that they _mean different things_: in `cmd.exe`, `cd..` is the same as `cd ..`; in PowerShell, `cd..` _as a whole_ is the (potential) name of a _command_ - and indeed there is such a command, created to keep `cmd.exe` users happy; see my answer for details. – mklement0 Oct 05 '19 at 22:14
  • 2
    @mklement0 I recognized too late that I should have written: The command line `cd..` is syntactically not 100% correct although working. Yes, `cmd.exe` executes also `cd..` and ``cd..\`` and `cd..\OtherFolder` although there is no space between command `cd` and its parameter `..` or ``..\`` or `..\OtherFolder`because of an error exception handling. This error handling can be seen on using free Sysinternals (Microsoft) [Process Monitor](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon). – Mofi Oct 06 '19 at 09:13
  • 2
    @mklement0 `cmd.exe` searches first in current directory for a file with name `cd` on using `cd..` which is usually not found and therefore results in error result *NAME NOT FOUND*. Then `cmd.exe` reinterprets the command line and executes `cd ..`. The search for a file `cd` does not occur on using `cd ..`. `cmd.exe` searches first for a file with name `cd.` in current directory on using ``cd..\`` with result *NAME NOT FOUND* before changing to parent directory which does not occur on using ``cd ..\`` with a space between command `cd` and parameter ``..\``. – Mofi Oct 06 '19 at 09:17
  • 2
    @mklement0 And last but not least `cmd.exe` searches in current directory for `cd.\OtherFolder` on using `cd..\OtherFolder` with result *PATH NOT FOUND* before changing the current directory to peer directory `OtherFolder`. The error condition does not occur with using 100% correct `cd ..\OtherFolder`. The execution of `cd..` in a cmd window results in error message if the current directory contains a file with name `cd` while `cd ..` works fine. The creation of a directory/file with name `cd.` is usually prevented by Windows, but can be achieved with using ``\\?\`` to bypass that prevention. – Mofi Oct 06 '19 at 09:29
  • 2
    @mklement0 Microsoft explains some of the auto-corrections usually done on not 100% correct entered file or directory arguments on documentation page [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). I prefer telling beginners 100% correct syntax and not a syntax working in 99.999999999 % of all uses cases due to error handling and auto-correction. Other example: `for %I in (C:/Windows/*.exe) do @echo %I` with not correct `/` as directory separator versus `for %I in (C:\Windows\*.exe) do @echo %I` with ``\`` as directory separator. – Mofi Oct 06 '19 at 09:36
  • I appreciate the additional information, @Mofi. So that means that `cd..` in PowerShell actually works more robustly, though something like `cd..\Foo` doesn't work at all. – mklement0 Oct 06 '19 at 14:33

2 Answers2

3

.. in filesystem paths represents a given path's parent path.

Without an explicit path preceding the .., the implied path is the current [working] directory, so the .. therefore refers to the current directory's parent directory.

In short: cd with an argument of .. changes to the current directory's parent directory, i.e., the directory one level above in the directory hierarchy.

Shell-specific use of .. with cd:

  • The legacy command processor, cmd.exe ("Command Prompt") - seemingly with the internal cd command specifically (see Mofi's comments on the question) - considers an . character to implicitly start the cd command's argument.

    • Therefore, separating the cd command from the .. argument with a space character, as usual, isn't necessary; that is, instead of cd .. you can type cd.., which is a shortcut that users of cmd.exe have grown accustomed to over the years.
  • PowerShell allows . characters to be used in command names, so submitting cd.. does not invoke the cd command (a built-in alias for the Set-Location cmdlet) with argument .. - instead, it looks for a command literally named cd..

    • To accommodate cmd.exe users who are accustomed to the cd.. shortcut, PowerShell comes with a parameter-less function literally named cd.., so that submitting cd.. as a command in PowerShell effectively works the same as in cmd.exe.

      • However, note that only cd.. works, not also specifying additional components; that is, something like cd..\Foo (which works in cmd.exe) fails.
    • Get-Command cd.. | Format-List shows information about this function, which reveals that it simply calls Set-Location .., which is PowerShell's equivalent of cmd.exe's cd ..

mklement0
  • 382,024
  • 64
  • 607
  • 775
1

These two dots mean "One upper level in the directory".

cd specifies to change the directory and .. means "upper level". So, cd.. means exactly what you stated in your question.

Example: let's say you are in the folder C:\x\y. If you type cd.., you'll be on C:\x

Bogdan Doicin
  • 2,342
  • 5
  • 25
  • 34