Suppressing Output from a Linux Command
Posted by: MikeW Date: 2015-08-04 09:49 Tags: linux, commandline, bash Tweet
After executing a Linux command have you ever wanted to suppress all of the output? I have and I finally found the answer. Turns out the answer is pretty straightforward.
Here is a typical example. I execute
gedit and send the output to the bit bucket.
gedit > /dev/null
The command sends standard output to the
null device. However, any output that would be sent to standard error still appears in the terminal window.
To turn off standard error, you can pass a modifier to the expression. Here is the list of options.
> /dev/nullredirects stout to the null device
1> /dev/nullsame result as the previous command
2> /dev/nullredirects sterr to the null device
&> /dev/nullredirects sterr and stout to the null device
So to prevent any output in the terminal window the following command would be used:
gedit &> /dev/null
So to start the command as a background process would be:
gedit &> /dev/null &
And finally, to execute a command in the background without making it a child process of the terminal use this.
(gedit &> /dev/null &)
This command will launch
gedit in its own process and prevent any output from appearing in the terminal.