Linux - 17 Special Characters in the Shell That You Should Know

Linux - 17 Special Characters in the Shell That You Should Know

 

There are a lot of characters that have special meaning to the shell.

Here are 17 of those special characters in the Shell with examples on how to use them.

1. Shortcut for the current user’s home directory

~

Example:

vim ~/.bashrc

2. Escape/Ignore next character

\

Example:

echo \$4

3. Directory separator

/

Example:

cd /home/bobby/logs

4. Variable, precedes any var

$

Example:

my_var="Hello World"
echo $my_variable

5. Single-character wildcard

?

Example:

ls *.l?g

6. Single quotation mark - escapes the special characters

Example:

echo ‘I've got $100’

7. The back tick is used for substitution

`

Example:

echo `date`

8. Double quotation marks, unlike the single quotation marks, the special characters between the quotes would be executed as normal rather than being escaped.

"

Example:

echo "Cost: $your_var"

9. Wildcard

*

Example:

 ls /var/log/secure*.*

10. Start a process in the background

&

Example:

redshift &

11. If command1 returns true, then do command2

&&

Example:

command1 && command2

 

12. If command1 returns false, then do command2

||

Example:

command1 || command2 

13. Pipe output to a program

|

Example:

 ls –l | grep my-file.txt

14. Execute multiple commands on one like

;

Example:

command1 ; commandd2

15. Ranges of letters and numbers

[]

Example:

ls logs[0-9]

16. Redirect output to a file

>

Example:

echo "Hello world" > ~/tmp/world.txt

17. Redirect input to a program

<

Example:

mysql my_database < my_backup.sql

Once you know a good number of those you could then start using them together and do lots of cool stuff!

If you want to learn more about Linux, I strongly recommend the following book:

 

Coffee For Me
Recent Posts
Proxies Demystified
Proxies Demystified
2019-11-05 09:31:05