1

I want to make a directory with the name being the day. I have this variable:

[Desktop]: $dia
21/02/16

created this way:

dia=$'date +%d/%m/%y'

I'm trying to make a new directory this way:

mkdir "$dia"
mkdir: date +%d/%m: No such file or directory

and

mkdir $dia
mkdir: date: File exists
mkdir: +%d/%m: No such file or directory

but it creates a directory named date.

How can I make this? Thanks!

1
  • 2
    I assume, you are using bash. Functions use parentheses, i.e. dia=$(date +<format>). You are using the string date +%d/%m for the dirs. Do NOT use slashes in your date format, as they are for subdirectories! Check the variable by echo $dia and you will understand the problem better.
    – FelixJN
    Feb 21 '16 at 11:57
3

Here's how to make a directory with day and time

now=$(date +"%Y.%m.%d_%H.%M.%S")
mkdir ${now}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.