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

pomsky
  • 68,507

1 Answers1

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.

thomasrutter
  • 36,774
  • 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 05:46
  • Thanks for this information, I added to the answer and made it community wiki. – thomasrutter Feb 15 '18 at 11:19