Ubuntu – What does // mean in a path

command linepaths

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?

Best Answer

/ 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)?