What does double slash // in `cd //` mean in Linux? [duplicate]

ⅰ亾dé卋堺 提交于 2020-02-26 07:48:11

问题


I've entered a command cd // instead of cd / by mistake and instead of getting an error as I'd expect the shell (Bash) showed a prompt as if I'm in the // directory:-

<username>@<hostname>://$
<username>@<hostname>://$ pwd
//

Listing the content of the directory shows that it is the same as /.

So what exactly cd // do and what's the difference from cd /?


回答1:


Actually it means nothing and is ignored.

From the Bash FAQ E10::

E10) Why does 'cd //' leave $PWD as '//'?

POSIX.2, in its description of 'cd', says that three or more leading slashes may be replaced with a single slash when canonicalizing the current working directory.

This is, I presume, for historical compatibility. Certain versions of Unix, and early network file systems, used paths of the form //hostname/path to access 'path' on server 'hostname'.

Also the Unix standards states:

A pathname that begins with two successive slashes may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash.




回答2:


This answer on AskUbuntu confirms that they are the same directory. Further, it helpfully quotes from the POSIX Pathname Resolution specification:

A pathname consisting of a single slash shall resolve to the root directory of the process. A null pathname shall not be successfully resolved. A pathname that begins with two successive slashes may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash.



来源:https://stackoverflow.com/questions/20690828/what-does-double-slash-in-cd-mean-in-linux

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