Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I redirect all output to /dev/null?

I want to run a program (google-chrome) in the background, but prevent it from outputting any messages to the terminal.

I tried doing this:

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

However, the terminal still fills up without messages like:

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

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

like image 246
Benubird Avatar asked Aug 02 '13 09:08

Benubird


People also ask

What does redirect to Dev Null do?

The operator '>' , called a redirection operator, writes data to a file. The file specified in this case is /dev/null. Hence, the data is ultimately discarded. If any other file were given instead of /dev/null, the standard output would have been written to that file.

How do I redirect all outputs to a terminal?

Method 1: Single File Output Redirection“>>” operator is used for utilizing the command's output to a file, including the output to the file's current contents. “>” operator is used to redirect the command's output to a single file and replace the file's current content.

How do you redirect a process of output?

The way we can redirect the output is by closing the current file descriptor and then reopening it, pointing to the new output. We'll do this using the open and dup2 functions. There are two default outputs in Unix systems, stdout and stderr. stdout is associated with file descriptor 1 and stderr to 2.

How do I redirect all stdout to a file?

Redirecting stdout and stderr to a file: The I/O streams can be redirected by putting the n> operator in use, where n is the file descriptor number. For redirecting stdout, we use “1>” and for stderr, “2>” is added as an operator.


1 Answers

Redirection operators are evaluated left-to-right. You wrongly put 2>&1 first, which points 2 to the same place, as 1 currently is pointed to which is the local terminal screen, because you have not redirected 1 yet. You need to do either of the following:

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

Or

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

The placement of the redirect operators in relation to the command does not matter. You can put them before or after the command.

like image 198
Michael Martinez Avatar answered Sep 24 '22 17:09

Michael Martinez