Silence or Redirect Console Output to a file in Linux

To silence all console output for a command, you can redirect the output to

> /dev/null 2>&1

STDOUT (1) will be redirected by the first > to /dev/null (you can also give a file here) and STDERR (2) will be captured by 2> for redirection. You can give a different filename here or use &1 to use the same location as STDOUT (1).

This works for commands in the command line and also for services. Here are two examples for silencing:

date > /dev/null 2>&1

service httpd restart > /dev/null 2>&1

Here two examples to redirect to one file (same file for both STDOUT and STDERR)

date > /tmp/datefile 2>&1

service httpd restart > /tmp/httpoutput 2>&1

Lastly two examples to redirect to different files:

date > /tmp/datefile 2> /tmp/datefileerrors

service httpd restart > /tmp/httpoutput 2> /tmp/httperrors