Search code examples
linuxrootcdpwd

What does cd // means (change directory to //)


I'm still a Linux newbie and I'm wondering: What is the Linux directory // ?

I can change dir (cd) to the root dir using cd /

~> cd /
/>

Using pwd (print name of working directory) tells me I'm in root (/)

/> pwd
/

Using ls (list directory contents) I see the following (using Raspbian Jessie)

/> ls
bin  boot  dev  etc  home  include  lib  lost+found  media  mnt  opt  proc  root  run  sbin  share  srv  sys  tmp  usr  var

By mistake I changed dir to // and found that it was valid:

~> cd //
//>

Also using pwd tells me I'm in a directory called // :

//> pwd
//

But using ls I see the that I'm probably still in 'something' looking like root.

//> ls
bin  boot  dev  etc  home  include  lib  lost+found  media  mnt  opt  proc  root  run  sbin  share  srv  sys  tmp  usr  var

... but telling me it's called // (rootroot ;-)

So what is directory // ?


Solution

  • In Linux (and most other platforms), multiple slashes in a path are interpreted the same as a single slash. However, the POSIX specification states that:

    A pathname that begins with two successive slashes may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash.

    // may be reserved for a special purpose (e.g: accessing a network drive in Cygwin). However, if you check ls in / and // on Linux you should see the same content.