1

I have 10,000 images in my folder. I am trying to resize them to 128 x 128.

sips -Z 128 *.jpg

is giving me this error:

-bash: /usr/bin/sips: Argument list too long

How do I fix this issue?

Mint.K
  • 849
  • 1
  • 11
  • 27

3 Answers3

3

Assuming you are in the folder you want to process...

find ./ -name "*jpg" -exec sips -Z 128 {} \;

should work, and be processing them one by one instead of one big argument list.

ivanivan
  • 2,155
  • 2
  • 10
  • 11
2

You could try executing the task in a single and simple for loop:

for file in *.jpg; do
 sips -Z 128 "$file"
done;

single line script:

for file in *.jpg; do sips -Z 128 "$file"; done;
Gustavo Topete
  • 1,246
  • 1
  • 9
  • 15
  • Nope as far as I know, bash executes one command per line sentence, and it will wait for sips to finish to start the next one. In other words, this will execute sips once per image, while the command in the question post tries to execute sips for all images at once. If I'm wrong please correct me – Gustavo Topete May 04 '18 at 23:23
2

Do them in smaller batches as suggested by the other answers.

Here's a third alternative that unlike the others allows you to parallelize the task. This example runs up to 4 parallel batches at a time, with a batch size of 100:

find . -name '*.jpg' -print0 | xargs -0 -n 100 -P 4 sips -Z 128

If you have a fast drive and more cores, you can increase the -P CPU count. If you have larger images and want more fine grained batches, you can reduce the -n batch count.

that other guy
  • 116,971
  • 11
  • 170
  • 194