Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

grep -i 'abc' content 2>/dev/null 
share|improve this question
up vote 77 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
Is there a good reason to use > /dev/null 2>&1 instead of &> /dev/null? – Craig McQueen Nov 30 '15 at 6:43
@CraigMcQueen &> is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember). – Terry Wang Nov 30 '15 at 12:24

dev/null treated as black hole in Linux/Unix, so you can put any this into this but at the end your will not able to get this back from /dev/null/.

so further on 2>, means is you are redirecting [i.e. ">"] stderr [i.e. 2] into black hole [i.e. /dev/null/ ]

this is your command : grep -i 'abc' content 2>/dev/null 

i hope this would help you.

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
There is absolutely nothing wrong if you use 2>/dev/null. These 2 are equivalents: > file and >file. And why grep -ri? – Radu Rădeanu Sep 26 '13 at 9:02
By the way, he could also be looking for the string /support/security/bulletins/ in the file called content =). – Alaa Ali Sep 26 '13 at 9:06
@RaduRădeanu the wrong syntax is not on 2> but he has probably reversed the grep arguments, since otherwise grep is unlikely to produce lots of errors, except not being able to open a file named "content". – sivann Sep 27 '13 at 12:24
@sivann That's a bad assumption. So, where is the wrong syntax? The OP doesn't said nothing about this... He just wanted to know what it means 2>/dev/null – Radu Rădeanu Sep 27 '13 at 15:02

Your Answer


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.