0

Hi i need to create a series of folder with a range of date for exmaple

createdir 2010-02-02 2010-02-05

will create :

20100202/ 20100203/ 20100204/ 20100205/

What the best way to do this with a Shell Script or with a C POSIX program?

1
  • Stackoverflow maybe? Mar 30, 2011 at 23:26

1 Answer 1

2

This question was answered in https://stackoverflow.com/questions/4351282/how-to-generate-a-sequence-of-dates-given-starting-and-ending-dates-using-awk-of . I like the @camh answwer.

You can create a shell script with this content,

#!/bin/bash
#./createdir 2010-02-02 2010-02-05

startdate=$1
enddate=$2

for d in $(seq $(date +%s -d $startdate) +86400 $(date +%s -d $enddate)); do
  mkdir $(date +%Y%m%d -d @$d)
done
2
  • ./date_script.sh 2011-01-01 2011-01-02 date: invalid date @1.29396e+09' date: invalid date @1.29387e+09' Why does that happens?
    – Necronet
    Mar 31, 2011 at 14:13
  • This code works in Ubuntu. Sounds like date command don´t understend the date format, YYYY-MM-DD. Try to call date with different date formats, for example, cturiel@menta:~/tmp$ date +%s -d 2010-02-02 1265065200 cturiel@menta:~/tmp$ date +%s -d 20100202 1265065200 cturiel@menta:~/tmp$ date +%s -d 2010/02/02 1265065200
    – cturiel
    Mar 31, 2011 at 21:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .