Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want one or two line description about the following command line:

grep -i 'abc' content 2>/dev/null 
share|improve this question

3 Answers 3

up vote 33 down vote accepted

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.

share|improve this answer

In short, it redirects stderr (fd 2) to the black hole (discard output of the command).

Some more common use case

command > /dev/null 2>&1 &

run command in background, discard stdout and stderr

command >> /path/to/log 2>&1 &

run command and redirect stdout and stderr to log file

share|improve this answer

This grep command has a wrong syntax, It should be something like

grep -ri content /support/security/bulletins/ 2> /dev/null

and the 2> /dev/null means to redirect all errors produced by this command to /dev/null, that is discard them, and don't display them to the screen (or where the standard error file descriptor is currently pointing). /dev/null is a file that when you write data to it they go nowhere.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.5.22.2603\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    Ubuntu and Canonical are registered trademarks of Canonical Ltd.\r\n                </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-wa"], "copyright__copyright__copyright": ["e 2> /dev/null means to redirect all errors produced by this command to /dev/null, that is discard them, and don't display them to the screen (or where the standard error file descriptor is currently pointing). /dev/null is a file that when you write data to it they go nowhere.\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}