Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For a test, I need to quickly create 1700 jpg-images (even blank) in a defined size 1000x706. I wonder if we could do this with a shell script or a program (like ImageMagick). I wish they called img_0.jpg, img_1.jpg

Someone knows a simple solution?

share|improve this question
up vote 21 down vote accepted

The following should work for your needs:

convert -size 1000x706 xc:white img_0.jpg || { printf '%s\n' 'Failed to create original image' ; exit 1 ; }
for (( _num = 1 ; _num < 1700 ; _num++ )); do
   cp img_0.jpg "img_${_num}.jpg" || { printf '%s\n' "Failed to copy to image img_${_num}.jpg" ; exit 2 ; }

ImageMagick creates the first image, and then it is copied to make up 1700 files. If ulimit doesn't restrict you from doing it (it probably will) and you have enough file descriptors, you could replace the loop with:

tee img_{1..1699}.jpg > /dev/null < img_0.jpg

You could also use the shorter idiom (with a larger memory requirement to store all of the numbers at once) for _num in {1..1699} in recent bash versions, but you don't specify which shells are available. (( is available in most shells (bash, ksh, and ash at least, not sure about others).

share|improve this answer
Thank you for your help. I try this in a few hours. Thank you for the idea =) I vote for your answer as soon as I have enough points – Raphaël Sep 22 '11 at 12:20

Your Answer


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.