What Does Double Slash // in 'Cd //' Mean in Linux

What does double slash // in `cd //` mean in Linux?

Actually it means nothing and is ignored.

From the Bash FAQ E10::

E10) Why does 'cd //' leave $PWD as '//'?

POSIX.2, in its description of 'cd', says that three or more leading
slashes may be replaced with a single slash when canonicalizing the
current working directory.

This is, I presume, for historical compatibility. Certain versions of
Unix, and early network file systems, used paths of the form
//hostname/path to access 'path' on server 'hostname'.

Also the Unix standards states:

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.

What does double slash mean in the file path?

This has no effect in file paths. The file system will treat them as a single slash.

These paths are all the same:

a/b
a//b
a///////b
a/./b
a/../a/b

What does two dots before a slash mean? (../)

Each directory has two entries in it at the start, with names . (a link to itself) and .. (a link to its parent directory). The exception, of course, is the root directory, where the .. directory also refers to the root directory.

What is double dot(..) and single dot(.) in Linux?

They are special name-inode maps which do count as hard-links (they do increase the link-count) though they aren't really hard-links, since, as you said, directories can't have hard-links. Read more here: Hard links and Unix file system nodes (inodes)

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

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.

What is the difference between \ and \\ in file path

Windows ignores double backslashes. So while the second syntax with \ is correct and you should use that one, the first with \\ works too.

The only exception is double-backslash at the very beginning of a path that indicates a UNC path.

See Universal Naming Convention.


Though note that in many programming languages like C, C++, Java, C#, Python, PHP, Perl, a backslash works as an escape character in string literals. As such, it needs to be escaped itself (usually with another backslash). So in these languages, you usually need to use a double backslash in the string literal to actually get a single backslash for a path. So for example in C#, the following string literal is actually interpreted as C:\Personal\MyFolder\MyFile.jpg:

var path = "C:\\Personal\\MyFolder\\MyFile.jpg";

Though there are alternative syntaxes. For example in C#, you can use the following syntax with the same result:

var path = @"C:\Personal\MyFolder\MyFile.jpg";

Forward slash vs backward slash for file path in git bash

Bash treats backslash as an escape character, meaning that the symbol following it is interpreted literally, and the backslash itself is dropped.

$ echo $HOME
/home/user
$ echo \$HOME
$HOME

Under Windows, where backslash serves as a path separator, this causes some inconvenience. Fortunately, inside single quotes a backslash character loses its special meaning and is treated literally (as any other character, except a single quote):

$ echo '\$HOME'
\$HOME

Therefore, if you are going to copy&paste a Windows path into Git bash, put it inside single quotes:

git diff > 'D:\Patches\afterWGComment.txt'

What is path //, how is it different from /

From Bash FAQ:

E10) Why does `cd //' leave $PWD as `//'?

POSIX.2, in its description of `cd', says that *three* or more leading
slashes may be replaced with a single slash when canonicalizing the
current working directory.

This is, I presume, for historical compatibility. Certain versions of
Unix, and early network file systems, used paths of the form
//hostname/path to access `path' on server `hostname'.


Related Topics



Leave a reply



Submit