1. Ampersand (&)
With the help of Ampersand we can run any linux command in background and go and grab
coffee.
Run two command in background, simultaneously:
2. semi-colon (;)
With the help of semi-colon we can run, several linux commands in a single go and the
execution of command occurs sequentially.
The above command combination will first execute update instruction, then httpd service
status instruction and finally will create a ‘test‘ directory under the current working directory.
3. AND (&&)
With the help of AND Operator (&&) we can execute the second command only, if the
execution of first command success. This command is very useful in checking the execution
status of last command.
For example, I want to visit website www.abhishekamralkar.in using lynx command, in
terminal but before that I need to check if the host is live or not.
www.abhishekamralkar.in
4. OR (||)
With the help of OR Operator (||) we can execute second command only if the execution of
first command fails, i.e., the exit status of first command is ‘1‘.
For example, I want to execute ‘yum update -y‘ from non-root account and if the first
command fails, then the second ‘lynx www.abhishekamralkar.in‘ command will execute.
5. NOT (!)
With the help of NOT Operator we can execute all commands command except the condition
provided. To understand this, create a directory abhishek in your home directory and ‘cd‘ to it.
abhishek@myfedora:~$ cd abhishek
Next, create several types of files in the folder abhishek.
See we’ve created all the new files within the folder abhishek.
a.doc a.html a.pdf a.xml b.doc b.html b.pdf b.xml
Now delete all the files except ‘html‘ file all at once, in a smart way.
Just to verify, last execution. List all of the available files using ls command.
abhishek@myfedora:~/abhishek$ ls
a.html b.html
6. AND – OR operator (&& – ||)
Its a combination of ‘AND‘ and ‘OR‘ Operator.
For example, let’s do ping to www.abhishekamralkar.in, if success echo ‘Verified‘ else echo
‘Host Down‘.
echo "Host Down"
7. PIPE (|)
With PIPE output of first command acts as an input to the second command. For example,
pipeline the output of ‘ls -l‘ to ‘less‘ and see the output of the command.
8. Command Combination {}
Combine two or more commands, the second command depends upon the execution of the
first command.
For example, check if a file ‘linux.txt‘ and ‘unix.txt‘ is available under my Downloads directory
or not, and output corresponding output.
exist”
abhishek@myfedora:~$ [ -f /home/abhishek/Downloads/unix.txt ] || echo “The file does not
exist”
“The file does not exist”
9. Precedence ()
The Operator makes it possible to execute command in precedence order.
In the above pseudo command, what if the Command1 fails? Neither of the Command2,
Command3, Command4 would executed, for this we use Precedence Operator, as:
In the above pseudo command, if Command1 fails, Command2 also fails but Still Command3
and Command4 executes depends upon exit status of Command3.
10. Concatenation (\)
With the help of Concatenation Operator (\) as the name specifies, is used to concatenate
large commands over several lines in the shell. For example, The below command will open text file test(1).txt.