9 Linux Terminal Special Characters That You Should Know
What are special characters?
There are a set of characters the linux shell treats in two different ways.
When you type them at the shell, they act as instructions or commands
and tell the shell to perform a certain function. Think of them as single-
character commands.
1) Home Directory ( ~ )
The tilde (~) is short hand for your home directory. It means wherever you are in the filesystem you do not have to explicitly specify you home address.
Tilde (~) can also be used with relative paths. Suppose you are somewhere in your filesystem that’s not under your home folder & you want to change to space-cloud directory in your space-up directory.
2) Current Directory ( . )
You can use the period in commands to represent the path to your current directory. For example, if you want to run a excutable binary from the current directory, you would call it like this:
By this way terminal look for the file in the current directory only, it won’t search for directories in your path for the executable or script.
3) Parent Directory ( .. )
The double period represents the parent directory of your current one. You can use this to move one level above in the directory tree.
Using (..) with relative paths for moving one level above in the directory tree & entering anothe directory at that level.
4)Path Directory Separator ( / )
Forward slash (/) represents the shortest possible directory path.Because everything in the Linux directory tree starts at the rootdirectory, you can use this command to move to the root directory.
Forward slash is used to seperate directories in pathplane.
5) Background Process ( & )
After you type a command in a terminal window and it completes, you
return to the command prompt. Normally, this only takes a few seconds.
But if you launch another application, such as gedit , you cannot use your terminal window until you close the application.
You can, however, launch an application as a background process and
continue to use the terminal window. To do this, just add an ampersand
to the command line.
6) Output Redirection ( > )
You can use right angle bracket to redirect output of a command (typically, into a file).
Output redirection can also redirect error messages of commands to a file if you digit 2 in the command.
7) Pipe ( | )
A “pipe” chains commands together. It takes the output from one command and feeds it to the next as input. The number of piped commands (the length of the chain) is arbitrary.
Here, we’ll use cat to feed the contents of the files.txt file into grep ,
which extracts any line that contains either a lower- or uppercase “C.”
grep will then pass these lines to sort . sort is using the -r (reverse)
option, so the sorted results will appear in reverse order.
8) Variable Expressions ( $ )
In the terminal, you create variables to hold values. Some, like
environment variables, always exist, and you can access them any time
you open a terminal window. These hold values, such as your
username, home directory, and path.
You can use echo to see the value a variable holds — -just precede the
variable name with the dollar sign ($).
To create a variable, you must give it a name and provide a value for it
to hold. You do not have to use the dollar sign to create a variable. You
only add $ when you reference a variable, such as in the following
example:
9) Character Sequence Wildcard ( * )
You can use the asterisk (*) wildcard to stand for any sequence of
characters, including no characters.
This matches all of the following:
It matches “new.txt” because the wildcard represents any sequence of
characters or no characters.
This command matches all files called “source,” regardless of the file
extension.