3

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.

6

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 '18 at 13:47
3

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'

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.