Beginners – BASH Special Characters

Valic —  November 29, 2012 — 1 Comment

Before we continue to study about UNIX operating system shell commands, it is important to understand that there are several symbols and characters that the shell interprets in special ways called BASH Special Characters. This means that certain typed characters:

  • Cannot be used in certain situations
  • May be used to perform special operations
  • Must be “escaped” if you want to use them in a normal way.
Character Explanation

\

Escape character. If you want to reference a special character, you must “escape” it with a backslash.
Example: touch filename\* – This command will create the file filename*

/

Directory separator. It’s used to separate a string of directory names.
Example: /var/www/htdocs

.

Current directory

..

Parent directory

~

User’s home directory

*

Represents 0 or more characters in a filename or by itself, all files in a directory.
Example: sql*2012 can represent the files sql2012, sql-backup2012, sql29-11-2012 etc.

?

Represents a single character in a filename.
Example: filename?.txt can represent filename1.txt, filenamex.txt.

[]

Can be used to represent a range of values,  [0-9], [A-Z], etc.
Example: filename[0-2].txt represents the names filename0.txt, filename1.txt, and filename2.txt

|

“Pipe” . It’s mostly used to redirect the output of one command into another command.
Example: ls | more

>

Redirects output of a command into a new file. If the file already exists will be over-writed.
Example: ls > listoffiles.txt

>>

Redirects the output of a command onto the end of an existing file. If the file does not exist, will be created.
Example: echo “test ” >> testfile.txt

<

Redirects a file as input to a program.
Example: more < listoffiles.txt

;

Command separator. Allows you to execute multiple commands on a single line.
Example: cd /var/log ; less syslog

&&

Command separator as above, but only runs the second command if the first one finished without errors.
Example: cd /var/logs && less syslog

&

Execute a command in the background, and immediately get your shell back.
Example: find / -name log > logfiles.txt &

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

One response to Beginners – BASH Special Characters

  1. Cool, I never knew about “>>”

Leave a Reply

*

Text formatting is available via select HTML. <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>