Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Stackoverflow maybe? –  Joseph Kern Mar 30 '11 at 23:26

1 Answer 1

This question was answered in http://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
share|improve this answer
    
./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 '11 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 '11 at 21:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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