How to Redirect Standard Output and Standard Error

Learn how to Redirect standard output and Standard Error in Linux and macOS. This tutorial covers both basic and advanced redirection techniques, including how to redirect to files, append to files, and redirect to other commands.

  1. Run the following find command, noting that both standard output and standard error are returned:
    find /etc -name passwd
  2. Rerun the command, saving standard output to a file:
    find /etc -name passwd > /tmp/find.out
  3. This time, save error message:
    find /etc -name passwd 2> /tmp/find.err
  4. Now, save the ordinary output to one file and the error message to a different file:
    find /etc -name passwd > /tmp/find.out 2> /tmp/find.err

Leave a Comment