Question

I'm looking for a script to copy and rename one single file in a folder 60 times with backward sequential day in OS X

For example diary.list becomes

20140320_diary.list

20140319_diary.list

20140318_diary.list

20140317_diary.list

20140316_diary.list

....

20140120_diary.list

I know this simple script to copy and rename with previous date to it

cp diary.list $(date -v -1d '+%Y%m%d')_diary.list

But how do I put -1d in a loop so that it repeats 60 times?

Thanks heaps!

Was it helpful?

Solution

for i in `seq 1 60`; do cp -v diary.list $(date -v -`echo $i`d '+%Y%m%d')_diary.list ; done

Omit -v from the cp command to quiet output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top