What is the double slash (//) directory?
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
/
Solution 1:
//
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.