Thursday, October 15, 2015

What does 2>/dev/null mean and 2>&1…?

What does this command actually do?

~]# grep -i 'abc' content 2>/dev/null

The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.
If you don't specify a number then the standard output stream is assumed but you can also redirect errors
> file redirects stdout to file
1> file redirects stdout to file
2> file redirects stderr to file
&> file redirects stdout and stderr to file
/dev/null is the null device it takes any input you want and throws it away. It can be used to suppress any output.


~]# ./executable_script.sh | tee 2>&1 /tmp/filename.log

Allows you to execute a script and view all errors on the console and output to  a log file for viewing afterwards. This helps to view any errors that scroll past your the console screen to fast.

No comments:

Post a Comment