Sometimes it's nice to generate a filename based on the current date and time.
In the Unix bash shell, you call the date command with a format string in back ticks
mystring=`date "+%y%m%d-%H%M%S"`
Or for just the date portion:
mystring=`date "+%y%m%d"`
Yes, but use capital Y to get a 4 digit year.
mystring=`date "+%Y%m%d-%H%M%S"`
Y2K was only a few years ago. My files with automatic filenames from the 80's still sort in 'ls' properly with new files.
date "+%Y_%m_%d-%H:%M:%S"
is more human readable, and still does proper date/time sorting with 'ls'.
I have over a million files in my home directory (tree) on my home system. Some date to the 1970s. So, yes, they predate my use of Linux. My point is that you've no idea how long files will last. And you can even want old files retroactively (crossing the century boundary).
Posted by: Stephen | June 22, 2009 at 11:08 AM