33

I mistakenly typed cd // instead of cd /. To my surprise, current directory showed up as //.

What is that directory? Why does it exist?

apple@snipped $ pwd
/home/apple
apple@snipped $ cd /
apple@snipped $ pwd
/
apple@snipped $ cd //
apple@snipped $ pwd
//
apple@snipped $ cd ///
apple@snipped $ pwd
/
muru
  • 197,895
  • 55
  • 485
  • 740
Zabba
  • 3,555

1 Answers1

48

// is usually the same as /. /// must be the same as /.

ls would have shown you that cd // took you to the root directory, the same as cd / does.

$ cd /
$ ls
bin
boot
dev
...
$ cd //
$ ls
(same as above)

The technical way to confirm they are definitely the same directory is:

$ cd /
$ stat -c "%i" .
2
$ cd //
$ stat -c "%i" .
2

they will print the same inode number, meaning they are the same thing.

The gory details are documented in 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.

Mikel
  • 6,558
  • 1
    Probably something POSIX left open for an equivalent to Windows UNC paths in case a UNIX wanted to do something like \\hostname\..., similar to how file://hostname/... is valid but implementation-defined. – ssokolow Feb 01 '21 at 01:33
  • 1
    Note that it is not limited to UNC-like meanings; see https://unix.stackexchange.com/questions/256497/on-what-systems-is-foo-bar-different-from-foo-bar – o11c Feb 07 '22 at 20:06