4

When I change directory to //, it seems to put me in a special directory that is very similar to but slightly different to /. However, trying to add any further slashes (///) simply drops me in /.

$ cd /    ;pwd
/
$ cd //   ;pwd
//
$ cd ///  ;pwd
/
$ cd //// ;pwd
/

It seems that // is somehow special, even though it has the same directories and everything, it's still a different string returned by pwd. Why is this? Why can my working directory be // but not ///?

Shelvacu
  • 669

1 Answers1

8

// is a special case, covered in the POSIX definition of the word "Pathname":

Multiple successive <slash> characters are considered to be the same as one <slash>, except for the case of exactly two leading <slash> characters.

On most systems // is the same as /, but it is allowed to be different according to POSIX.

Further reading:

(I think the first of these links is the best.)

Wildcard
  • 36,499
  • 1
    I have been using Unix/SunOS/Linux/etc for 20+ years, and yet... TIL. "If a pathname begins with two successive characters, the first component following the leading characters may be interpreted in an implementation-defined manner, although more than two leading characters shall be treated as a single character." – Aaron D. Marasco May 05 '16 at 20:52