5

This question already has an answer here:

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?

marked as duplicate by Eliah Kagan, Braiam, Eric Carvalho, Pandya, Sylvain Pineau Sep 20 '14 at 7:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

  • 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 Sep 19 '14 at 21:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.