Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I just found a very weird feature (bug?) with my computer's file system. I can do cd // and it will go to the // directory, but display all the same files as the / directory. Why is this? If I cd .. while in /, it will stay at /. // is the only one that works -- I tried multiple slashes, but it just stays in /.

share|improve this question
    
What does /bin/pwd report when you're in //? Also, which shell are you using? –  larsmans Mar 16 '12 at 19:26
    
@larsmans pwd tells me I'm in //. I'm using bash. –  CoffeeRain Mar 16 '12 at 19:28
1  
Is that pwd or /bin/pwd? –  larsmans Mar 16 '12 at 19:29
    
Both say the same thing. –  CoffeeRain Mar 16 '12 at 19:31
    
Same results on ubuntu. // is root. –  Jason Huntley Mar 16 '12 at 19:32
show 2 more comments

migrated from stackoverflow.com Mar 16 '12 at 19:36

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 8 down vote accepted

From the POSIX spec:

3.266: ... Multiple successive slashes are considered to be the same as one slash.

4.11: ... 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.

The second part means that a path beginning with // can have a special meaning. This is rarely if ever used, and can be a source of bugs: http://stackoverflow.com/a/7816833/163956.

share|improve this answer
    
Mostly correct, but you're conflating pathnames and URLs in the last paragraph. They're different concepts defined in different specs. –  larsmans Mar 16 '12 at 19:37
    
Fair enough, edited. –  Greg Inozemtsev Mar 16 '12 at 19:48
add comment

There is no difference between // and /. It's just bash being tolerant of multiple slashes.

Note you can also use // in paths and it won't complain, and it will treat them just like /.

share|improve this answer
add comment

It seems like Bash will normalize pathnames, but does not normalize double slashes at the beginning of a pathname. This is understandable, as on some Unix systems (though not Mac OS X), // may indicate a network path and Bash is intended to be portable. See this question on Unix.SE for the double-slash issue.

Since in Mac OS X // has no special meaning, you're actually in /.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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