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?

4
  • 1
    What makes you think that // is "needed"?
    – fkraiem
    Sep 19, 2014 at 15:49
  • When you ask why // is needed, do you just mean, why does // need to be treated separately from /? Sep 19, 2014 at 16:12
  • @EliahKagan You are right .I mean if // is not different from / then why people created this Sep 19, 2014 at 16:14
  • Also visit: askubuntu.com/q/483129/256099
    – Pandya
    Sep 20, 2014 at 4:32

1 Answer 1

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

1
  • 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. Sep 19, 2014 at 21:46

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