8

I am using mogrify to resize the images in a directory using the following command

    mogrify -resize 100x100 *.jpg

due to the huge number of images, I get the following error

    /usr/bin/mogrify: Argument list too long

Any suggestions?

Thanks

Shan
  • 18,563
  • 39
  • 97
  • 132

3 Answers3

30

Actually, the answer is surprisingly simple. Rather than having the shell expand the argument list (which it cannot cope with), let ImageMagick expand the list itself internally, by protecting the arguments from the shell with single quotes.

So, your command becomes:

mogrify -resize 100x100 '*.jpg'

If the built-in glob expression does not work for you (eg. special file ordering), you may also use the special character '@':

mogrify -resize 100x100 @my_jpegs.txt
malat
  • 12,152
  • 13
  • 89
  • 158
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
3

find or xargs come to mind, eg.

find . -name \*.jpg -exec mogrify '{}' -resize 100x100 \;

Cheers,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
  • It didn't help me. Most shells limit the length of the command line. We can get around this by using ImageMagick filename globbing methods. So instead of `mogrify -resize 50% *.jpg` use `mogrify -resize 50% "*.jpg"`. I use this command: `find . -name \*.png -exec mogrify '{}' -format jpg "*.png" \;` It works on 130k+ files. – SlyDeath Dec 02 '19 at 06:53
1

magick said

Most shells limit the length of the command line. You can get around this by using ImageMagick filename globbing methods. So instead of mogrify -resize 50% *.jpg use mogrify -resize 50% "*.jpg"

Your case would be

mogrify -resize 100x100 "*.jpg"
Ax_
  • 803
  • 8
  • 11