ls exists 1> stdout.txt # Redirect the standard output to a file
ls noexist 2> stderror.txt # Redirect the standard error output to a file
ls > out.txt 2>&1 # Redirect standard output and error to a file
# similar examples
cat exists.txt > output.txt 2>&1
cat output.txt
#foo
#bar
#baz
cat noexist.txt > output.txt 2>&1
cat output.txt
#cat: nop.txt: No such file or directory
Standard Output, Standard Error and Standard Input
File descriptors and redirection