golb

Bash

Redirection

# override to FILE
cmd > FILE
# append to FILE
cmd >> FILE
cmd &> FILE

cmd >& FILE

redirect stdout and stderr to FILE

cmd | cmd2

The standard output of cmd is connected via a pipe to the standard input of cmd2.

cmd |& cmd2

cmd's standard error, in addition to its standard output, is connected to cmd2's standard input through the pipe

Standard input

cmd < FILE
cmd <<< "string"

Pipe

CMD_1 | CMD_2

Multiple commands

CMD_1 ; CMD_2 ; CMD_3

Background task

CMD &

Conditional commands

CMD_1 && CMD_2
CMD_1 || CMD_2

Shell tricks

!! # last command
 ls # with a trailing space -> not in history

disown -a && exit # leave terminal but don't kill running processes