Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect the output of an application in background to /dev/null

Tags:

linux

ubuntu

I would like to redirect the output generated from a background application in Linux to /dev/null.

I am using kate text editor and it prints all the debug messages on the terminal which I would like to redirect to /dev/null.

Any idea how to do it ?

Thanks

like image 353
Kiran Avatar asked Nov 21 '11 23:11

Kiran


People also ask

How do I redirect only stderr to Dev Null?

Similarly, to redirect only the STDERR to /dev/null, use the integer '2' instead of '1' . The integer '2' stands for standard error. As you can see, the standard error is not displayed on the terminal now as it is discarded in /dev/null.

How do I redirect program output to a file?

the shortcut is Ctrl + Shift + S ; it allows the output to be saved as a text file, or as HTML including colors!

What does piping to Dev Null do?

In technical terms, “/dev/null” is a virtual device file. As far as programs are concerned, these are treated just like real files. Utilities can request data from this kind of source, and the operating system feeds them data. But, instead of reading from disk, the operating system generates this data dynamically.

How do I redirect the output of an already running process?

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 to redirect error and output messages to/dev/null?

You can send output to /dev/null, by using command >/dev/null syntax. However, this will not work when command will use the standard error (FD # 2). So you need to modify >/dev/null as follows to redirect both output and errors to /dev/null. Syntax to redirect error and output messages to /dev/null

How to send output to/dev/null in Linux?

You can send output to /dev/null, by using command >/dev/null syntax. However, this will not work when command will use the standard error (FD # 2). [donotprint][/donotprint]So you need to modify >/dev/null as follows to redirect both output and errors to /dev/null.

How to redirect stdout to/dev/null in Linux?

Now, to redirect only the STDOUT to /dev/null, i.e. to discard the standard output, use the following: What does ‘1>/dev/null’ mean? Here '1' indicates STDOUT, which is a standard integer assigned by Linux for the same. The operator '>', called a redirection operator, writes data to a file. The file specified in this case is /dev/null.

What does >/dev/null 2>&1 mean?

Any idea how to do it ? >/dev/null 2>&1 means redirect stdout to /dev/null AND stderr to the place where stdout points at that time If you want stderr to occur on console and only stdout going to /dev/null you can use: In this case stderr is redirected to stdout (e.g. your console) and afterwards the original stdout is redirected to /dev/null


1 Answers

You use:

yourcommand  > /dev/null 2>&1 

If it should run in the Background add an &

yourcommand > /dev/null 2>&1 & 

>/dev/null 2>&1 means redirect stdout to /dev/null AND stderr to the place where stdout points at that time

If you want stderr to occur on console and only stdout going to /dev/null you can use:

yourcommand 2>&1 > /dev/null 

In this case stderr is redirected to stdout (e.g. your console) and afterwards the original stdout is redirected to /dev/null

If the program should not terminate you can use:

nohup yourcommand & 

Without any parameter all output lands in nohup.out

like image 91
evildead Avatar answered Sep 20 '22 20:09

evildead