What is path //, how is it different from /?
Asked Answered
U

1

22

We know the root directory is /, and according to POSIX, there is another directory // which differs from /.

When you ls / and ls //, the output is the same, so is stat, however if you cd / and cd //, they are different, though the directory content are the same.

That really confused me. Anyone got an answer?

Umlaut answered 30/5, 2013 at 16:5 Comment(4)
Can you provide a reference which says they are different? Also, what do you mean if you "cd /" vs. "cd //" they are different -- how do you know?Tonsillotomy
@MarkkuK. Sorry I didn't say it clear, it means pwd didn't change. So as devnull said. You can try it.Umlaut
Additionally, if you type "cd //usr" (for example) instead of "cd /usr", you end up in "/usr", bash says you are un "//usr" and pwd is "//usr" too...Sematic
How does Linux handle multiple consecutive path separators (/home////username///file)?Aquarium
H
28

From Bash FAQ, with formatting applied:

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.

Herald answered 30/5, 2013 at 16:32 Comment(1)
On my git bash emulation (technically a windows machine) an attempt to ls -l // results in the machine trying to read and list the entire available network... wow.Hepler

© 2022 - 2024 — McMap. All rights reserved.