10

I was working in my terminal, when I misspelled while cd to root (/). Accidentally, I typed // and I got in terminal:

root@weblocalhost://#

When i type pwd, i get response // but when I type ls -s i got same list as in / directory.

When you type more than 2, i.e. /// you get:

root@weblocalhost:/#

Always 1 / except for 2. Is there any difference and what is // for?

muru
  • 197,895
  • 55
  • 485
  • 740

2 Answers2

10

/ is equivalent to //

From the POSIX specification (emphasis added):

3.267 Pathname

A string that is used to identify a file. In the context of POSIX.1-2008, a pathname may be limited to {PATH_MAX} bytes, including the terminating null byte. It has optional beginning <slash> characters, followed by zero or more filenames separated by <slash> characters. A pathname can optionally contain one or more trailing <slash> characters. Multiple successive <slash> characters are considered to be the same as one <slash>, except for the case of exactly two leading <slash> characters.

And:

4.12 Pathname Resolution

...
A pathname consisting of a single <slash> shall resolve to the root directory of the process. A null pathname shall not be successfully resolved. If a pathname begins with two successive <slash> characters, the first component following the leading <slash> characters may be interpreted in an implementation-defined manner, although more than two leading <slash> characters shall be treated as a single <slash> character.

For a nice discussion of exceptions (cygwin and directories) see: How does linux handle multiple consecutive path separators (/home////username///file)?

Panther
  • 102,067
4

You can add multiple slashes to a directory and it will not change anything. E.g. these three commands all do the same:

cd /home
cd /home/
cd /home//

After any of these my current working directory is is set to /home (check with pwd).

I guess that you have your prompt configured to do something smart and that you ran into unanticipated behaviour. What do you get when you echo $PS1 ?

Check this comment on unix.stackexchange.com which may explain it.

Pablo Bianchi
  • 15,657
Hennes
  • 1,233
  • My PS1 in bash on OSX is "\h:\W \u$" and I get this strange behavior, too. / and /// and //// and ///// all show up as /, but the special case of two forward slashes shows up as two forward slashes. – Sparr Mar 28 '13 at 16:55
  • I got the \u@\h:\w (user at host, working dir) in Ubuntu 12.10 but I fail to reproduce the problem. – Hennes Mar 28 '13 at 16:58
  • no i get always // when checking pwd in any case. for echo $PS1 i get: [\e]0;\u@\h: \w\a]${debian_chroot:+($debian_chroot)}\u@\h:\w$ – Dimitris Theodoridis Mar 28 '13 at 16:59
  • I just manually set my PS1 and I can not reproduce it with two slashes. Weird. Not with 1, 3 or 4. Only with 2. I am at a loss to explain this. – Hennes Mar 28 '13 at 17:07
  • Maybe this comment from unix.stackexchange is the answer: I believe that Windows POSIX compat APIs will also treat //remote/... the same as the UNC path \remote... format. – Stephen P Jan 20 '11 at 0:39 – Hennes Mar 28 '13 at 17:09