When I want to go back to upper level directory in Linux by typing cd .., I typo-ed cd //. To my great surprise, no errors are reported. What's more the prompt becomes username@hostname://$. ls indicates that I'm now at root directory.

Is this a bug or a feature of the shell? If a feature, is // an alias of /? My shell is GNU bash, version 4.1.5(1)-release (i686-linux-gnu).

Thanks and best regards.


It can be considered either.

In Linux, // means nothing – multiple consecutive slashes get collapsed to one, anywhere in the path, including the beginning. Changing directory to // puts you in /, as running readlink /proc/self/cwd would tell; likewise, /usr//local///bin is collapsed to /usr/local/bin.

However, some other Unix-like systems, for example Cygwin or the old Apollo Domain/OS, use the // prefix for network paths such as //fileserver/path/to/data. POSIX allows this as well.

For various reasons, the bash shell tracks the current directory on its own (in addition to the OS-provided tracking) and it has code in it that prevents the initial // from being collapsed, to remain compatible with such systems. The "feature" is that bash provides more intuitive tracking of current directory, for example, when cd'ing into a symlink, bash will show you the path you expect, even though the kernel thinks otherwise. The "bug" is that bash permits // even on systems that do not use it.

| improve this answer | |
  • Interestingly, zsh allows cd //, but is smart enough to just show / in the prompt string. – new123456 Apr 6 '12 at 0:53
  • @BinaryZebra Bitsavers has a collection of old Unix manuals, including Apollo's – there should be plenty of examples there. The TUHS website should have something as well. – user1686 Jan 20 '16 at 20:13
  • Many thanks, I found the description for // in the Bitsavers manual. – user353322 Jan 21 '16 at 2:27

From the POSIX pathname definition:

A pathname may optionally contain one or more trailing slashes. Multiple successive slashes are considered to be the same as one slash.


And more precisely as grawity mentioned in his comment below, from the 4.11 chapter on Pathname Resolution:

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.

| improve this answer | |
  • 1
    A more proper section is 4.11 Pathname Resolution (last paragraph), since the behavior in question only appears for two leading slashes. – user1686 Feb 13 '12 at 15:42

It a kind of feature. If you've got shell script going and use find, for example all paths are prefixed with ./ usually. Then, if you tack that onto an actual path it becomes `/my/path/./appended/path, which resolves to /my/path/appended/path. So, if I'm not mistaken, // get's interpreted as /./ and therefore /. This is the same for if you went to /home/user//, you'd wind up in /home/user/

| improve this answer | |

I would go for prompt displaying "bug".

Either paths "/", "//", "//////////////////////", ... have the same meaning: "/". You can add as many "/" wherever you want in an Unix path, this not change its meaning.

The "bug" is more here related to the fact that your prompt use the last valid typed in path for display, not the actual "pwd".

Funny anyway ;)

| improve this answer | |
  • Agreed -- the // in the prompt is a side effect of your prompt environment variable ($PS1) -- how is PS1 defined? – Doug Harris Feb 13 '12 at 14:12
  • @DougHarris the $PS1 variable is defined as [\u@\h \W]\$. Any problem with setting? – Summer_More_More_Tea Feb 16 '12 at 1:08
  • Odd. If I try that PS1, I only get one / when pwd = /. I wondered if you were doing any extra work to get the directory. Is $PROMPT_COMMAND set? – Doug Harris Feb 16 '12 at 15:11
  • @DougHarris Yes, this variable is set, whose value is echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#HOME/~}"; echo -ne "\007". Could you pls explain in a little bit detail? I'm not quite familiar with these two variables. Thanks. – Summer_More_More_Tea Feb 21 '12 at 8:47
  • Read the bash man page and search for PS1 and PROMPT_COMMAND -- use man bash at your command line or read online – Doug Harris Feb 21 '12 at 14:39

Its a Feature and all multiple // will be replaced to one single /

Its useful if you have variables with paths like the example at the end. So your cd wouldn't get any error and you don't have to change the workspace variable.


the complete content of the project variable is


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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