As we all know "unix" can have anything in a file except '/' and '\0', sysadmins however tend to have a much smaller preference, mainly due to nothing liking spaces as input ... and a bunch of things having a special meaning for ':' and '@' among others.
Recently I'd seen yet another case where a timestamp was used in a filename, and after playing with different formats a bit to make it "better" I figured I'd try to find a "best practice", not seeing one I figured I'd just ask here and see what people thought.
Possible "common" solutions (p=prefix and s=suffix):
syslog/logrotate/DNS like format:
p-%Y%m%d-suffix = prefix-20110719-s p-%Y%m%d%H%M-suffix = prefix-201107191732-s p-%Y%m%d%H%M%S-suffix = prefix-20110719173216-s
pros:
- It's "common", so "good enough" might be better than "best".
- No weird characters.
- Easy to distinguish the "date/time blob" from everything else.
cons:
- The date only version isn't easy to read, and including the time makes my eyes bleed and seconds as well is just "lol".
- Assumes TZ.
ISO-8601- format
p-%Y-%m-%d-s = p-2011-07-19-s p-%Y-%m-%dT%H:%M%z-s = p-2011-07-19T17:32-0400-s p-%Y-%m-%dT%H:%M:%S%z-s = p-2011-07-19T17:32:16-0400-s p-%Y-%m-%dT%H:%M:%S%z-s = p-2011-07-19T23:32:16+0200-s
pros:
- No spaces.
- Takes TZ into account.
- Is "not bad" to read by humans (date only is v. good).
- Can be generated by $(date --iso={hours,minutes,seconds})
cons:
- scp/tar/etc. won't like those ':' characters.
- Takes a bit for "normal" people to see WTF that 'T' is for, and what the thing at the end is :).
- Lots of '-' characters.
rfc-3339 format
p-%Y-%m-%d-s = p-2011-07-19-s p-%Y-%m-%d %H:%M%:z-s = p-2011-07-19 17:32-04:00-s p-%Y-%m-%d %H:%M:%S%:z-s = p-2011-07-19 17:32:16-04:00-s p-%Y-%m-%d %H:%M:%S%:z-s = p-2011-07-19 23:32:16+02:00-s
pros:
- Takes TZ into account.
- Can easily be read by "all humans".
- Can distinguish date/time from prefix/suffix.
- Some of the above can be generated with $(date --iso={hours,seconds})
cons:
- Has spaces in the time versions (which means all code will hate it).
- scp/tar/etc. won't like those ':' characters.
I love hyphens:
p-%Y-%m-%d-s = p-2011-07-19-s p-%Y-%m-%d-%H-%M-s = p-2011-07-19-17-32-s p-%Y-%m-%d-%H-%M-%S-s = p-2011-07-19-23-32-16-s
pros:
- basically a slightly nicer syslog/etc. variant.
cons:
- Lots of '-' characters.
- Assumes TZ.
I love hyphens, with extensions:
p.%Y-%m-%d.s = p.2011-07-19.s p.%Y-%m-%d.%H-%M.s = p.2011-07-19.17-32.s p.%Y-%m-%d.%H-%M-%S.s = p.2011-07-19.23-32-16.s
pros:
- basically a slightly nicer "I love hyphens" variant.
- No weird characters.
- Can distinguish date/time from prefix/suffix.
cons:
- Using '.' here is somewhat non-traditional.
- Assumes TZ.
...so anyone want to give a preference and a reason, or more than one (Eg. don't care about TZ if it's 95+% to stay machine local, but care a lot if it isn't).
Or, obviously, something not in the above list.