17

The command mogrify -format jpg *.NEF when run in a directory converts all *.NEF files to JPEGs. What I want to do is to be able to run mogrify in *.NEF files inside subdirectories as well using one command. I am trying to run something like:

find . -type d exec mogrify -format jpg *.NEF \;

and of course it is not working. Can someone suggest the proper command?

Cristian Ciupitu
  • 5,513
  • 2
  • 37
  • 47
Regmi
  • 845
  • 3
  • 15
  • 30

1 Answers1

23

It looks like mogrify from ImageMagick 6.9.9.19 writes the result in the same directory as the input file, so you can use this command:

find . -name '*.NEF' -exec mogrify -format jpg {} +

Explanation:

  • -name '*.NEF' finds all *.NEF files; use -iname if you want the search to be case insensitive.

  • -exec ... {} + executes the command on all the matching files. An alternative would be to combine find with xargs.

Cristian Ciupitu
  • 5,513
  • 2
  • 37
  • 47
  • Just a tip, you may want to expand on this a little as it was marked as low quality. Consider explaining what the command does in detail. –  Oct 20 '13 at 03:05
  • Working perfect. I use this for convert svg to png with: "find . -name '*.svg' -exec mogrify -format jpg {} +" – Indacochea Wachín Jan 24 '19 at 23:05