5

What is the difference between cd / and cd //? We can see that adding / to the end doesn't do anything. But when I do cd // and pwd, I found:

$ cd //
$ pwd
//  

What is difference between / and //? An ls in both directories shows the same content. Why is // needed?

terdon
  • 100,812

1 Answers1

10

/ and // are pointing to same directory. See repeated slahes in a path are equivalent to a single slash

This behavior is mandated by POSIX and most applications follow suit. The exception is that “a pathname that begins with two successive slashes may be interpreted in an implementation-defined manner”.

What you're seeing is not, in fact, Linux doing anything special with // it's bash's current directory tracking.

$ bash -c 'cd //; pwd'
//
$ bash -c 'cd //; /bin/pwd'
/

source

sourav c.
  • 44,715
  • For a brief discussion of “bash’s current directory tracking” (although not directly relevant to this question), see Strange difference between pwd and /bin/pwd. TL;DR The shell keeps track of what it thinks the working directory is. This may differ from the truth. The best known examples are (1) cd into a symlink, and (2) cd into a directory, and then rename it. Apparently this is a third example, where the shell remembers that you cd’ed to // just in case that’s different from / on this system, without bothering to check. – G-Man Says 'Reinstate Monica' Sep 19 '14 at 21:46