How to redirect all output to / dev / null?

I want to run the program (google-chrome) in the background, but not allow it to output any messages to the terminal.

I tried to do this:

google-chrome 2>&1 1>/dev/null & 

However, the terminal is still full without messages, such as:

[5746: 5746: 0802/100534: ERROR: object_proxy.cc (532)] Could not call the method: org.chromium.Mtpd.EnumerateStorag ...

What am I doing wrong? How to redirect all output to /dev/null ?

+53
bash pipe dev-null
Aug 2 '13 at 9:07 on
source share
3 answers

Redirection operators are evaluated from left to right. what you did wrong was first placed 2>&1 , which points 2 to the same place as 1 currently indicates what is the local terminal screen because you haven't redirected 1 yet. You need to do the following:

 2>/dev/null 1>/dev/null google-chrome & 

or

 2>/dev/null 1>&2 google-chrome & 

The placement of redirection operators with respect to the command does not matter. You can place them before or after the command.

+56
Aug 02 '13 at 19:38
source share

The Redirection bash section of the reference manual says:

The [n]>&word operator is used [...] to duplicate output file descriptors

To redirect both stderr and stdout to file , you should use the form

 &>file 

For your case, this means replacing

 2>&1 1>/dev/null 

from

 &>/dev/null 
+32
Aug 02 '13 at 9:19 on
source share

The syntax seems to be different:

 ./a.out 1>/dev/null 2>&1 & 

See the devices for FD = 2 are different when ./a.out 1>/dev/null 2>&1 and ./a.out 2>&1 1>/dev/null &

1) FD = 2 points to / dev / null

 >./a.out 1>/dev/null 2>&1 & [1] 21181 >lsof -p `pidof a.out` COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME a.out 21181 xxxxxxxxxxxxxxx 0u CHR 136,43 0t0 46 /dev/pts/43 a.out 21181 xxxxxxxxxxxxxxx 1w CHR 1,3 0t0 3685 /dev/null a.out 21181 xxxxxxxxxxxxxxx 2w CHR 1,3 0t0 3685 /dev/null 

2) FD = 2 points to / dev / pts / 43

 >./a.out 2>&1 1>/dev/null & [1] 25955 >lsof -p `pidof a.out` COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME a.out 25955 xxxxxxxxxxxxxxx 0u CHR 136,43 0t0 46 /dev/pts/43 a.out 25955 xxxxxxxxxxxxxxx 1w CHR 1,3 0t0 3685 /dev/null a.out 25955 xxxxxxxxxxxxxxx 2u CHR 136,43 0t0 46 /dev/pts/43 
+1
Aug 02 '13 at 9:19 on
source share



All Articles