Search This Blog

Saturday, September 5, 2015

Formatting dates in Linux for sensible log file names

I like to make my log filenames have date stamps and so in my shell scripts I typically will create a log file name at the start of the script:

# Create name for log file
timenow=`date +%Y%m%d-%H%M%S`
logfilename="utils-${timenow}.log"

and the time will now be included in the log filename.

You can remove the %S to take off the seconds if you want.


No comments:

Post a Comment