Redirecting Standard Error
Instead of redirecting the standard output to a file, you can redirect the error messages to a file. This can be done by placing a 2 directly in front of the redirection angle bracket. If you are not interested in the error messages, you simply can send them to /dev/null
This shows you the location of file foo, if it exists, without those pesky permission denied error messages. I almost always invoke the find command in this way.
The number 2 represents the standard error output stream. Standard error is where most commands send their error messages. Normal (non-error) output is sent to standard output, which can be represented by the number 1. Because most redirected output is the standard output, output redirection works only on the standard output stream by default. This makes the following two commands equivalent:
$ find / -name foo 1> output.txt
$
piping the output to another command.
Leave a Reply
You must be logged in to post a comment.