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.
- Run the following find command, noting that both standard output and standard error are returned:
find /etc -name passwd
- Rerun the command, saving standard output to a file:
find /etc -name passwd > /tmp/find.out
- This time, save error message:
find /etc -name passwd 2> /tmp/find.err
- 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