Error:

Redirect standard output to file

ls -lR > ls-lR

Redirect standard error to file

cmd 2>errors.txt

Redirect both standard output and error to file

cmd &> file.txt

Redirect file descriptor output to file

# redirects filed desc 3 to file three.txt
cmd 3>file.txt

Redirect file descriptor to another descriptor

# Redirect file descriptor 3 to stdout
cmd 3>&1

Redirect stderr to stdout

cmd 2>&1

Redirect stderr to stdout to file

cmd > output.txt 2>&1

Truncate file

: > file.txt

Append standard output to file

cmd >> stdout.txt

Append standard error to file

cmd 2>>errors.txt

Open file and assign file descriptor to it

# open file.txt for output and assign file descriptor 3 to it
exec 3>&file.txt
# test goes to file.txt
echo test >&3

Close output file descriptor

# close stderr
exec 2>&-

Close input file descriptor

# close stdin
exec 0<&-

Redirect loop output

for s in One Two Tree; do
    echo "$s"
done | less

Send all output to standard error to a log file

exec 2>file.txt
# Will be printed to file.txt
ls -la notexist.really