How to hide the screen output (printf) of a shell application in Linux?

link|improve this question

74% accept rate
feedback

4 Answers

up vote 12 down vote accepted

You can redirect the output of any program so that it won't be seen.

$ program > /dev/null

This will redirect the standard output - you'll still see any errors

$ program &> /dev/null

This will redirect all output, including errors.

link|improve this answer
The first one didn't work for wget – Jader Dias Jul 17 '09 at 3:07
That's cause wget uses stderr for some of it's output. The second one should work. – theotherreceive Jul 17 '09 at 3:08
2  
Incidentally, you might want to save that wget output to a log file, so when/if your download stops working, you can figure out why. If it's in a script anyway. If this is a one-off type run, then yea, to the trash – Matt Simmons Jul 17 '09 at 3:17
For wget you can use the -q options to make it quiet. – pkhamre Mar 30 at 10:12
feedback

There are three IO devices available on the commandline.

 standard in - 0 
 standard out - 1 
 standard error - 2

To redirect standard out (the default output) to a file (and overwrite the file), use

 command > file.log

To append to file.log, use 2 >s

 command >> file.log

to redirect standard error to the file.log, use

 command 2> file.log

and to append

 command 2>> file.log

To combine the outputs into one stream and send them all to one place

 command > file.log 2>&1

This sends 2 (stderr) into 1 (stdout), and sends stdout to file.log

Notice that it's also possible to redirect standard in into a command that expects stdin

 command << file.txt

EDIT
For more details, check out the Advanced Bash Scripting Guide

link|improve this answer
pretty comprehensive! thanks – Jader Dias Jul 17 '09 at 3:11
You're welcome. Anytime! :-) – Matt Simmons Jul 17 '09 at 3:16
Can somebody explain how the command > file.log 2>&1 works? – nomoreink May 23 '11 at 22:37
How low of a level would you like to know? – Matt Simmons May 29 '11 at 13:54
feedback

For Mac OS X (10.6 "Snow Leopard"):

If you need to hide the output without letting the program know it by checking the output/error file descriptor you can try using the following in a shell:

stty flusho; command ;stty -flusho

or if you just want to hide input from the terminal by the way:

stty  -echo; command ;stty  echo

See stty(1) manual page for more information

For Linux all i know is that Ubunutu (10.04 "Lucid") and some "Debian/Arch" (commented below - tnx hendry) doesn't have the flusho setting (and i can't see anything other appropriate in the man-page). The echo setting works on the Ubuntu anyway.

link|improve this answer
My default stty under Debian/Arch does not have these options. – hendry Mar 3 at 4:46
I should of course have mentioned that i wasn't even on the OP's OS. Edited my post. – vike Mar 30 at 10:09
feedback

If you just want to hide the output (and not save it to a file), you can use:

Edited:

$ command &> /dev/null

link|improve this answer
This will redirect the output to a file called null – theotherreceive Jul 17 '09 at 3:03
It generated a null file – Jader Dias Jul 17 '09 at 3:04
you wouldn't have meant /dev/null, would you? – Babu Jul 17 '09 at 3:09
Yes, I would have, Babu. I meant $ command &> /dev/null. My apologies for typing too fast for my own good. – Lucho Jul 17 '09 at 3:13
feedback

Your Answer

 
or
required, but never shown

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