On my Linux box, in bash, I have access to a "double root" folder denoted by two forward slashes:

tomas:~ $ cd /
tomas:/ $ ls
bin/ cdrom@ ...
tomas:/ $ cd //
tomas:// $ ls 
bin/ cdrom@ ...

The content of the folder and its subfolder is identical to the "normal" single slash root. The double slash does not go away when I access its subfolders. The annomaly does not repeat itself with three or more slashes; these are simple synonyms for the root:

tomas:// $ cd home/tomas
tomas://home/tomas $ cd ///
tomas:/ $ cd ////
tomas:/ $

What kindof place is it? Is it a bug? Can anyone explain the annomaly?

link|improve this question
good question - i noticed the same behavior but never asked why this happens. – lajuette Sep 17 '10 at 14:50
feedback

5 Answers

up vote 13 down vote accepted

From Bash FAQ E10:

E10) Why does 'cd //' leave $PWD as '//'?

POSIX.2, in its description of 'cd', says that three or more leading slashes may be replaced with a single slash when canonicalizing the current working directory.

This is, I presume, for historical compatibility. Certain versions of Unix, and early network file systems, used paths of the form //hostname/path to access 'path' on server 'hostname'.

link|improve this answer
Thank you. Clear answer. – Tomas Sep 14 '10 at 14:45
1  
Domain/OS is one such system. – grawity Sep 14 '10 at 15:46
feedback

"It's not a bug, it's a feature!"

You're still in the same root directory. I don't know the origins of this, but suspect it may have something to do with building strings for absolute paths. If anyone else knows for sure, pipe up.

link|improve this answer
feedback

Multiple slashes are just ignored by the tools you have used and you are always getting to the same root folder.

link|improve this answer
So why does bash change /// into / while leaving // as is? – Tomas Sep 14 '10 at 12:07
feedback

Multiple slashes are treated as a single slash for pathname-resolution purposes.

What you're seeing in the shell prompt is an artifact of bash PS1 handling (see section "PROMPTING" in the bash manpage).

[root@linux /]# cd /    ; echo $PWD
/
[root@linux /]# cd //   ; echo $PWD
//
[root@linux //]# cd /// ; echo $PWD
/
[root@linux /]# cd //// ; echo $PWD
/

The result is only a matter of presentation; you're always in the same root directory. You can check this by looking at /proc/$$/root.

[edit] Well I never knew this: http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 The meaning of "//" is left undefined by the standards, but "///" and more slashes are equivalent to "/".

link|improve this answer
feedback

Or, maybe it's just like using a trailing slash for a directory.

ex. /home and /home/

So, treating / like the actual name of the directory, it would only be natural to be able to add a trailing slash.

Except when I try to cd into /home/ the prompt displays user@foobar:/home$

Oooh, mysterious.

It may also be some kind of legacy thing, for old obscure scripting languages.

Edit: Oops, sorry. The answer didn't register in my mind for a second, and I just wanted to give some input.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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