On the "prometheus-installation" lab, what does "/dev/null 2>&1 &" mean?

Hello everyone

On the solutions for this lab, when starting prometheus, this is presented:

./prometheus > /dev/null 2>&1 &

Also on a separate solution:

./node_exporter > /dev/null 2>&1 &

I get that with this, the program is not “stuck” in the command line. We can continue to write other commands but I do not understand this syntax. Could someone please explain it?

Thank you

Hello @miguelfranciscof
These are linux redirection approches.

>> /dev/null redirects standard output ( stdout ) to /dev/null , which discards it.

(The >> seems sort of superfluous, since >> means append while > means truncate and write, and either appending to or writing to /dev/null has the same net effect. I usually just use > for that reason.)

2>&1 redirects standard error ( 2 ) to standard output ( 1 ), which then discards it as well since standard output has already been redirected.

This way you can suppress all messages that might be issued by the executed command. In cron this is often done to avoid being spammed by lots of irrelevant messages from service scripts. Nevertheless be careful with this as some messages might be important.

1 Like