Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 have the original images in a directory structure that looks like this:

...the rest of the states...

I wanted to convert all of the original images into thumbnails so I can display them on a website. After a bit of digging / experimenting, I came up with the following Linux command:

find . -type f -iname '*.jpg' | sed -e 's/\.jpg$//' | xargs -I Y convert Y.jpg -thumbnail x100\> Y-small.jpg

It recursively finds all the jpg images in my subdirectories, removes the file type (.jpg) from them so I can rename them later, then makes them into a thumbnail and renames them with '-small' appended before the file type.

It worked for my purposes, but its a tad complicated and it isn't very robust. For example, I'm not sure how I would insert 'small-' at the beginning of the file's name (so ./Alabama/small-1.jpg).


  1. Is there a better, more robust way of creating thumbnails from images that are located in multiple subdirectories?
  2. Can I make the existing command more robust (for example, but using sed to rename the outputted thumbnail before it is saved- basically modify the Y-small.jpg part).
share|improve this question

If it is always just one level of directories below your position, you could try looping this way:

for dir in *; do
  [ ! -d "$dir" ] && continue; # skip non-directory entries, i.e. additional files
  cd "$dir"
  for file in *.jpg; do
    convert -thumbnail x100 "$file" "small-${file}" # creates e.g. small-1.jpg
share|improve this answer

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.