Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've looked at this question, and while it works there a few issues:

  1. All converted images are placed in the directory from which the command is called.
  2. The original images are kept.

I need to convert around 70,000 .tif and .jpgs to .pngs. It's really important the the files when converted are placed in their normal directories.

I can do a batch rm of .tff/.jpg's at the end if that's the best way to handle removing the old files.

share|improve this question
up vote 2 down vote accepted
for f in $(find . -iname "*.jpg" -type f) ;
    convert $f $(dirname $f)/$(basename -s .jpg $f).png ;
  • find . -iname "*.jpg" -type f : search for file ending with ".jpg" case insensitive
  • $(dirname $f) : relative path to the folder containing file $f
  • $(basename -s .jpg $f) : filename without the suffix ".jpg"

In old Ubuntu basename may need to be run with different way:

basename $f .jpg

Convert is a part of imagemagick (As reference see Batch Processing tif images: Converting .tif to .jpeg) , to install

sudo apt-get install imagemagick
share|improve this answer
Thanks, I get: basename: invalid option -- 's' Try `basename --help' for more information. A lot of times... – user2757729 Jan 16 '14 at 17:01
@user2757729 basename has a -s option in Ubuntu. Are you sure you are on Ubuntu? – gertvdijk Jan 16 '14 at 17:02
Try with basename --suffix=.jpg $f or basename $f .jpg – Sneetsher Jan 16 '14 at 17:05
looks like basename $f .jpg was the way to go – user2757729 Jan 16 '14 at 17:11
The find -iname finds foo.JPG too - but the basename $f .jpg does not handle that. – Volker Siegel Sep 25 '14 at 11:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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