I want to make the current date into the title of a directory in /home/chris/Downloads
by using mkdir
and date -I
I tried mkdir "date -I" that gets me a folder named "date -I" Without the quotes it gives the error
mkdir: invalid option -- 'I'
Trying to make it a variable next
date= date -I
mkdir -p $date
with the -p
option, it looked good, but upon inspection, the folder wasn't created.
removing -p
gets me the error
mkdir: cannot create directory `/home/chris/Downloads/': File exists
and even pointing it to the entire path
date= date -I
mkdir "/home/chris/Downloads/$date"
gets me the same error as before
It's not that the variable is empty, I echo'd it and the value is what I should expect, it seems to be that the value isn't substituted before the directory is created. What would be the way to get around this problem? I'm running Ubuntu 11.04 (Natty Narwhal) if that gives you any more info.
The command is date +%Y%m%d so that a directory for today would be 20060811.
Save this answer. Show activity on this post. $() means: "first evaluate this, and then evaluate the rest of the line". On the other hand ${} expands a variable.
To get the date in bash shell and add a date, you can use the GNU date command as date -d 'Feb 12 +1 day' +%F which will output 2020-02-13 . See the above section on GNU date for more examples on the -d option.
So as far as I can tell, %% doesn't have any special meaning in a bash function name. It would be just like using XX instead. This is despite the definition of a name in the manpage: name A word consisting only of alphanumeric characters and under- scores, and beginning with an alphabetic character or an under- score.
Your syntax is wrong:
mkdir -p /home/chris/downloads/$(date -I)
or
mkdir -p /home/chris/downloads/`date -I`
will work
Use this: backticks run the command instead of printing it out.
mkdir `date -I`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With