PDA

View Full Version : How can I make a folder's name the date in bash?



firebirdworks
August 16th, 2008, 07:25 PM
How can I make a new folder with the date as the name? Thanks.

bobbocanfly
August 16th, 2008, 07:28 PM
mkdir $(date +whatever_format)

For example:


mkdir $(date +%F)

Creates ./2008-08-16/

akudewan
August 16th, 2008, 07:29 PM
mkdir "`date`"


(The double quotes are for escaping the spaces, and the backquotes are for command substitution)

You can ofcourse use any of the options of the date command

jinksys
August 16th, 2008, 08:18 PM
How can I make a new folder with the date as the name? Thanks.


A lot of times mkdir `date +%F` is used in conjunction with a crontab, however, if you ever do this make sure you escape the percent sign in your crontab.



* * * * * mkdir `date +\%F`


You may never have to use this, but I thought I'd throw it out there to save you some time troubleshooting.