I have a folder containing many subfolders full of images. See attached image for example.


Basically I want to loop through them all and downsize the images so none are wider than 1024 pixels. They're all jpegs.

I'm aware of the SIPS commands i.e.

sips -Z 1024 *.png

However, that only works if all images are in the current directory.

How do I set it up to traverse through all subdirectories?


You can run it with find: find images/path -type f -name '*.png' -exec sips -Z 1024 {} \;

Find will search for files (-type f), with png extension (-name '*.png') inside 'images/path' directory and exec the command in parameter, replacing "{}" with the filename, you need to end the command with "\;".

  • Thanks. I had some issue with that not actually resizing all but did the same with imagemagick: find /images/path -type f -iname "*.jpg" -execdir convert {} -resize 1024x1024\> -quality 70 {} \;
    – Quadrant6
    Jul 21 '14 at 23:58
  • Thanks, I'm trying the sips command again, it runs through as if it's doing something but doesn't seem to actually save the new file..? find images/path -type f -name "*.jpg" -exec sips -Z 1024 -s format jpeg -s formatOptions 80 {} \;
    – Quadrant6
    Jul 22 '14 at 1:51
  • @Quadrant6 check if it's not saving the file in current directory, also test the sips command alone in the same path but specifying the full pathname for a test image file.
    – denisvm
    Jul 22 '14 at 1:53
  • 1
    perfect to remove files: find "FOLDER_NAME" -type f -name '*_16.png' -exec rm {} \; Thanks!!!!!
    – Guilherme
    Feb 2 '20 at 13:07
  • @Guilherme You can use -delete instead of -exec rm {} \; if you want just to remove files: find "FOLDER_NAME" -type f -name '*_16.png' -delete
    – denisvm
    Apr 17 '20 at 13:37

I managed to change a small bash script which worked for me


find "foldername" -type f | \
while read file ; do
    echo "processing ${file}"
    sips -Z 2000 ${file}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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