what does “..”(DotDot) mean in “cd..” command in powershell? [closed]

淺唱寂寞╮ 提交于 2021-02-08 07:30:10

问题


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




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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!