Make directory name date in bash?

I want to make the current date in the directory header in /home/chris/Downloads using mkdir and date -I

I tried mkdir "date -I" which gets me the named "date -I" folder. Without quotes, it gives an error

 mkdir: invalid option -- 'I' 

Trying to make it the next variable

 date= date -I mkdir -p $date 

with the -p option, it looked good, but after checking the folder was not created. removing -p causes an error

 mkdir: cannot create directory `/home/chris/Downloads/': File exists 

and even pointing all the way

 date= date -I mkdir "/home/chris/Downloads/$date" 

gets the same error as before

Not that the variable was empty, I read it, and the value is what I should expect, it looks like the value is not replaced before the directory is created. How can I get around this? I am running Ubuntu 11.04 (Natty Narwhal) if this gives you more information.

+7
source share
3 answers

Your syntax is incorrect:

 mkdir -p /home/chris/downloads/$(date -I) 

or

 mkdir -p /home/chris/downloads/`date -I` 

will work

+12
source

Use this: backticks run a command, not print it.

 mkdir `date -I` 
+3
source

You can also try xargs (however, not sure if this is good practice)

 date -I | xargs mkdir 
0
source

All Articles