-2

For the root directory a // will display in the prompt:

───────────────────────────────────────────────────────────────────────────────
rick@alien:~$ cd /
───────────────────────────────────────────────────────────────────────────────
rick@alien:/$ cd //
───────────────────────────────────────────────────────────────────────────────
rick@alien://$ cd ///
───────────────────────────────────────────────────────────────────────────────
rick@alien:/$ 

You can change to // directory. But when you change to /// directory it takes you back to /.

Sub-directories don't display the same way though:

───────────────────────────────────────────────────────────────────────────────
rick@alien:~$ cd /usr
───────────────────────────────────────────────────────────────────────────────
rick@alien:/usr$ cd /usr//src
───────────────────────────────────────────────────────────────────────────────
rick@alien:/usr/src$ 
───────────────────────────────────────────────────────────────────────────────
rick@alien:/usr/src$ cd //usr
───────────────────────────────────────────────────────────────────────────────
rick@alien://usr$ 
───────────────────────────────────────────────────────────────────────────────
rick@alien://usr$ cd ///usr
───────────────────────────────────────────────────────────────────────────────
rick@alien:/usr$ 

As you see // is automatically converted to a single / in sub-directories. However the rule doesn't apply to first level directories.

Why is // displayed for top level directories but not sub-directories?

  • It's come up a few times over on U&L e.g. Why can I cd to // but not /// or //// or ///// or … – steeldriver Feb 15 '18 at 1:51
  • @steeldriver Weird I got 5 points from U&L today on a closed question and was thinking I should be spending more time over there. Are you hinting these types of questions are best posted there instead of AU? – WinEunuuchs2Unix Feb 15 '18 at 1:56
  • IMHO it's a valid question here (although arguably more about POSIX than Ubuntu) - the U&L regulars may be better at the intricacies of these things – steeldriver Feb 15 '18 at 2:26
  • Incidentally, Zsh does not display the two slashes after cd //, neither in the prompt nor in pwd. – fkraiem Feb 15 '18 at 6:06
3

A second slash has no meaning and the proper behaviour is for the system to treat it as if it were a single slash.

Your shell is normalising the path so that it is shown without the additional slash in all cases except for one: when the path begins with just two slashes. The shell is preserving the second slash in this case according to POSIX standards which allow paths beginning with two slashes to have a special meaning defined by the context. In this context, however, there is no special meaning and it ends up being ignored even though the shell is preserving it.

  • 2
    POSIX requires that repeated slashes be treated as a single slash, except for the case of exactly two slashes at the start of a path (//foo as opposed to ///foo or /foo//bar), where the leading // is left the system to interpret specially if needed (network shares on Windows, nodes on QNX, etc.). – muru Feb 15 '18 at 5:46
  • Thanks for this information, I added to the answer and made it community wiki. – thomasrutter Feb 15 '18 at 11:19

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