Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

How can we redirect output of command to /dev/null?

I tried it with:

command > /dev/null

But it didn't work.

share|improve this question
    
Have you tried command 2>&1 > /dev/null? – YoMismo Oct 8 '15 at 9:57
    
It works thanks. – Zola Oct 8 '15 at 9:59
    
that work for me, what are you mean by "don't work"? Maybe you see the STRERROR, not the STROUTPUT. – feligiotti Oct 8 '15 at 10:00
    
that syntax I used won't work. @gio900 – Zola Oct 8 '15 at 10:01
1  
@YoMismo Since the OP has not explained what command he is using and whether it is printing to stdout or stderr, cuonglm is quite right in pointing out that what you show can fail. Even if it works for this particular case, it might not for the next person to read your comment and it's good to mention this. On the other hand, your comment is way out of line. If that's how you're going to behave towards others, then please do stay away. Rudeness is not acceptable. You're welcome to participate and I hope you do, but only if you can be civil. – terdon Oct 8 '15 at 11:53
up vote 1 down vote accepted

Your command had redirected standard output to /dev/null, but maybe the command printed to standard error instead of standard output, so you still see the text in terminal.

To redirect standard output and standard error to /dev/null, you need:

command >/dev/null 2>&1

Note that the order of redirection is important, swapping them to 2>&1 >/dev/null won't work because standard error was redirected to standard output at the time when standard output still point to terminal, you still see the text in terminal if command write to standard error.

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.