0

I use this command:

find . \( -iname '*.jpg' -o -iname '*.jpeg' \) -print0 | xargs -0 -n 1 -P 4 jpegoptim --max=70 -s

But it fails on some images (jpegoptim receive SEGFAULT) and crash xargs, and all process fail.

How to skip fails, and continue task?

Thank

1 Answers1

0

You could wrap it up in a scriptlet, like:

find . \( -iname '*.jpg' -o -iname '*.jpeg' \) -print0 | \
  xargs -I@ -0 -n 1 -P 4 sh -c 'jpegoptim --max=70 -s "@" || exit 0'

, note that above won't handle some funnily named files (like e.g. with " in it).

[update: fixed for sh -c '...' as per comments]

jjo
  • 2,595
  • 1
  • 8
  • 16
  • 1
    correct: find . \( -iname '*.jpg' -o -iname '*.jpeg' \) -print0 | xargs -I@ -0 -n 1 -P 4 sh -c 'jpegoptim --max=70 -s "@" || exit 0' – Artem Malahov Jun 05 '18 at 14:07