21

We know 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 as 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?

jww
  • 97,681
  • 90
  • 411
  • 885
dspjm
  • 5,473
  • 6
  • 41
  • 62
  • 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? – Markku K. May 30 '13 at 16:15
  • @MarkkuK. Sorry I didn't say it clear, it means pwd didn't change. So as devnull said. You can try it. – dspjm May 31 '13 at 02:04
  • 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... – Tom Feb 20 '18 at 11:56
  • 1
    [How does Linux handle multiple consecutive path separators (/home////username///file)?](https://unix.stackexchange.com/q/1910) – jww May 26 '19 at 20:46

1 Answers1

27

From Bash FAQ:

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'.
devnull
  • 118,548
  • 33
  • 236
  • 227
  • 4
    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. – Paul Hodges Oct 16 '17 at 16:15