Linux Date command: Show current date YYYY-DD-MM

Thursday, 29 May 2008

Linux Date command: Show current date YYYY-DD-MM

YYYY-MM-DD

echo `date +"%Y-%m-%d"`

Result:
2008-05-29

YYYY-MM-DD_HH_MM_SS
echo `date +"%Y-%m-%d_%H-%M-%S"`

Result:
2008-05-29_10-35-44
You can use these for creating files names of backups.


 Digg  Del.icio.us  Reddit  SlashDot

3 comments:

sanjay said...

The commands are simple and
easily explained

Svetoslav Marinov said...

Thanks :)
That's the idea.
Sometimes one needs the most important information nothing else.

Anonymous said...

I've got something better :-p

$ date
Fri Jul 10 10:57:36 CEST 2009
$ date --date='last thursday'
Thu Jul 9 00:00:00 CEST 2009
$ date --date='thursday 2 week ago'
Thu Jul 2 00:00:00 CEST 2009
$ date --date='thursday 2 week ago' +%Y%m%d
20090702


Inspired by:
http://www.basicconfig.com/linux/linux-date-command-tutorial

FYI:
I'll use this for creating incremental backups. I'll tar everything, what is newer than previous Thursday. Eg. `tar -cjf backup.tar.bz2 precious_data -N 20090702` <- this number I'll get via date command used as above.