Operators

The Command Operators allow users to control the flow of commands and processes in the terminal, offering greater flexibility and efficiency. Here is an explanation of their use:

  • Execute a command and send it to the background

$command &

  • Execute a list of commands

$command1 && $command2
$command1 ; $command2

When using && the next command will only be executed if the previous one was successful


  • Redirects the output of a command to a file

$command > $filename

If the file doesn't exist, it will be created, and if it exists, it will be overwritten


  • Redirects the output of a command to a file, but it appends it to the final instead of overwriting it

$command >> $filename

  • Takes content from a file

$command < $filename

  • Takes content from a stream

$command << $stream #Ex: cat << EOF   

  • Pass the result of a command as a parameter to another command

$command1 | $command2

  • Catch an error in a file

$command1 2>$filename

The number 2 indicates the STDERR. A common use is 2>/dev/null to discard any error

Last updated