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
/

1 Answer 1

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.

2
  • 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 1, 2021 at 1:33
  • 1
    Note that it is not limited to UNC-like meanings; see unix.stackexchange.com/questions/256497/…
    – o11c
    Feb 7, 2022 at 20:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .