4

I would like to know what the meaning of the backslash is when used in a path, e.g.:

ll /opt/deployment/release175/war-files\ files/

output, for example is:

accounting-module.war

finance-module.war

Thanks.

2 Answers 2

8

The backslash is the escape character to tell the shell not to interpret some special characters. In your case, it escapes the space character.

In shell, a space is normally used to split arguments. Without the backslash, your shell would interpret the space as usually. You would have 2 arguments to your ll call, which would probably lead to a "File or Directory not found" error.

Alternatively you could surround your argument with quotes:

ll /opt/deployment/release175/war-files\ files/
ll "/opt/deployment/release175/war-files files/"
ll '/opt/deployment/release175/war-files files/'

Backslash is also used to escape other special characters:

\(
\$
\{
\*
\#
\\
1
  • ... and under some circumstances \! when combined with other characters (interactive bash to avoid history expansion).
    – Kusalananda
    Nov 26, 2018 at 13:47
4

In Unix/Linux (or POSIX), the backslash is an escape character.

In that particular case, the backslash is escaping white space. If it weren't there then the ll command would attempt to operate on:

/opt/deployment/release175/war-files\

and

files/

You can also use double or single quotes

ll "opt/deployment/release175/war-files files/"

ll 'opt/deployment/release175/war-files files/'

The backslash can also be used to escape other special characters with other commands:

rpm -qa | postgre\*

grep \.regex file

sed 's/\/this\/path/\/that/\/path/g'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .