Linking Commands

Julia this is for you:-)

| command1 | command2
Linux shell pipes join the standard output of command1 to the standard input of command2. Output of the ps command is provided as the standard input to the grep command.
ps aux | grep bash

|| command1 || command2
Command2 is executed if, and only if, command1 returns a non-zero exit status i.e. command2 only runs if first command fails.
tar cvf user.tar.gz /home/user || mail -s ‘Backup failed’ user@domain.com < /dev/null && command1 && command2
Command2 is executed if, and only if, command1 returns an exit status of zero i.e. command2 only runs if first command1 run successfully.
apt-get update && apt-get upgrade

& command arg &
The shell executes the command in the background in a subshell. The shell does not wait until the command finish, and the return status is 0. The & operator runs the command in background while freeing up your terminal for other work. For example: find command is executed in background while freeing up your shell prompt.
find /home/user -name “*.jpg” > /tmp/usersjpg.txt &

; command1 ; command2
Separates commands that are executed in sequence. For example, ps is executed only after date command completes.
date ; ps

Leave a Reply

Your email address will not be published. Required fields are marked *

*