Redirection Output in Linux Bash/Shell

You can redirect outoput from a command into a file

cat filename filename2

and that will redirect all output. But you can also select the type of output

0 = Standard Input
1 = Standard Output
2 = Standard Error

So that this wil send error messages to nothing

cat filename 2/dev/null

Or explicitly send both standard output and standard error to a file with and ampersand (“&”)

docommand &filename

You can append to a file with double greater than signs (“>”)

docommand >filename

Or redirect standard error to standard output, and then send that to oblivion

docommand 2>&1 /dev/null

Note the ampersand on the right side to distinguish it from a filename

Leave a comment

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