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

I tried it with:

command > /dev/null

But it didn't work.

  • Have you tried command 2>&1 > /dev/null? – YoMismo Oct 8 '15 at 9:57
  • 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
  • what command your are trying for command > /dev/null? what it outputs? – Pandya Oct 8 '15 at 10:19
  • 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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.