Tuesday, September 26, 2023
rated 0 times [  15] [ 0]  / answers: 1 / hits: 18862  / 2 Years ago, tue, june 22, 2021, 3:29:07

On giving cd , I get the > symbol while cd / changes the ~ sign in my directory to /.

Also ls command shows me directories like dev, root, usr in case of cd /.

More From » command-line


In Bash, your shell, the (backslash) denotes an escape character. This should be used in cases where you want to escape characters like spaces, quotes and other characters meaningful to the shell syntax, but you want to have it propagate as data to the command you're running. By having this as the last character on the line you're escaping the newline and Bash is waiting for further input (multiple lines).

/ is just a forward slash (meaning directory separator). With just / this means the root, so for example ls / lists the contents of the root. By changing the working directory to /, the indicator in your shell also changes from ~ (short for home directory, e.g. /home/gert/) to the directory you're in then (/).


$ touch a filename with spaces
$ ls -l
total 0
-rw-rw-r-- 1 gert gert 0 Jul 1 02:33 a
-rw-rw-r-- 1 gert gert 0 Jul 1 02:33 filename
-rw-rw-r-- 1 gert gert 0 Jul 1 02:33 spaces
-rw-rw-r-- 1 gert gert 0 Jul 1 02:33 with

Oh noes, it was my intention to create one file with the name a filename with spaces. So, here we use the to escape the spaces. This prevents the shell to provide four arguments to touch, but instead provide a single one with the spaces included.

touch a filename with spaces

$ touch a filename with spaces
$ ls -al
total 24
drwxrwxr-x 2 gert gert 4096 Jul 1 02:35 .
drwxrwxr-x 55 gert gert 20480 Jul 1 02:33 ..
-rw-rw-r-- 1 gert gert 0 Jul 1 02:35 a filename with spaces

Of course, by using quotes (touch "a filename with spaces") one can achieve the same thing.

It is also used to declare special characters like newlines:

$ echo -e "bla
newline" #
means a newline character

We need the -e option here for echo, because as the manpage put it: -e enable interpretation of backslash escapes.

[#30515] Tuesday, June 22, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 82
Total Questions: 113
Total Answers: 106

Location: Saint Vincent and the Grenadines
Member since Wed, Nov 3, 2021
2 Years ago