问题
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.
回答1:
..
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 internalcd
command specifically (see Mofi's comments on the question) - considers an.
character to implicitly start thecd
command's argument.- Therefore, separating the
cd
command from the..
argument with a space character, as usual, isn't necessary; that is, instead ofcd ..
you can typecd..
, which is a shortcut that users ofcmd.exe
have grown accustomed to over the years.
- Therefore, separating the
PowerShell allows
.
characters to be used in command names, so submittingcd..
does not invoke thecd
command (a built-in alias for theSet-Location
cmdlet) with argument..
- instead, it looks for a command literally namedcd..
To accommodate
cmd.exe
users who are accustomed to thecd..
shortcut, PowerShell comes with a parameter-less function literally namedcd..
, so that submittingcd..
as a command in PowerShell effectively works the same as incmd.exe
.- However, note that only
cd..
works, not also specifying additional components; that is, something likecd..\Foo
(which works incmd.exe
) fails.
- However, note that only
Get-Command cd.. | Format-List
shows information about this function, which reveals that it simply callsSet-Location ..
, which is PowerShell's equivalent ofcmd.exe
'scd ..
回答2:
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
来源:https://stackoverflow.com/questions/58246025/what-does-dotdot-mean-in-cd-command-in-powershell