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

LinuxUbuntu

Linux Problem Overview


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

Linux Solutions


Solution 1 - Linux

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

Solution 2 - Linux

These will also redirect both:

yourcommand  &> /dev/null

yourcommand  >& /dev/null

though the bash manual says the first is preferred.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKiranView Question on Stackoverflow
Solution 1 - LinuxevildeadView Answer on Stackoverflow
Solution 2 - LinuxJim HunzikerView Answer on Stackoverflow