Redirect both stdout and stderr to /dev/null
:
> /dev/null 2>&1
OR in bash:
&> /dev/null
You can do it for all programs spawned by your script by using exec
with the redirection at the beginning of your script.
exec > /dev/null 2>&1
Unless the programs you invoke in your script access the terminal directly (rare), this should cover you.
One note on redirections:
The order matters. It needs to be > /dev/null 2>&1
, NOT 2>&1 >/dev/null
. I used to think the latter would work because >
looks like an arrow which makes me think of pointers (as does the word "redirect"), and if I point stderr to stdout and then point stdout to /dev/null, then both should be pointing to /dev/null. That is not the case, though. File descriptors are not pointers and it is more helpful to think of >
as sort of an assignment to a file descriptor rather than pointing. (Sort of, because technically, a fd is just a number and you need system functions like dup2
to open a different file into the same file descriptor; but I think assignment is a good high-level abstraction).
/dev/null
, or to a file in case you need it for subsequent diagnostics.mv /root/Desktop/lynis/plugins/* /etc/lynis/plugins/ &>/dev/null
. The pipe symbol sends the output to another program's input; redirection sends the output to a file: you can't do both (although that the program to which output is piped can have its own output redirected, as inprog1 | prog2 &> file3
).