Linux – Manipulate the stdout and stderr

Redirection is very common and useful in Linux.

  • stdout – Normal messages output displayed on terminal after running a command
  • stderr – Error messages displayed on terminal after running a command


Here are some examples for manipulate the stdout and stderr.

Redirect stdout to a file

  • cat <file> > result.txt

Redirect stderr to a file

  • cat <file> 2> result.txt

Redirect stderr to stdout (Show both stdout and stderr on terminal)

  • cat <file> 2>&1

Redirect the stderr and stdout to a file

  • cat <file> &> result.txt

Silence both the stdout and stderr

  • cat <file> &> /dev/null

Done =)

Reference: All about redirection

4 thoughts on “Linux – Manipulate the stdout and stderr”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.