Redirect command output to /dev/null

# my_cmd > /dev/null 2>&1

Redirect all of the output for an entire script. Add the following to the top of the line.

exec > /tmp/output 2>&1 # to redirect both in same file 

exec > /tmp/output 2>/tmp/error # to redirect in different files 

Need to redirect to a logfile and output some stuff to the console?

In your script:

DATE=`date '+%Y.%m.%d_%H.%M.%S'`
exec 3>&1 1>>/var/log/my.log.${DATE} 2>&1

echo "" 1>&3
echo "/var/log/my.log.${DATE} has been created" 1>&3
echo "" 1>&3

This will send the output to your logfile but print that your logfile has been created to the console.