0

I have a directory called src full of sub directories and other images. I tried to use one bash statement to automatically resize them all to another destination directory called thumb like this:

find ./src -type f -follow -iname '*.jp*g' -exec convert -resize 150x150x "{}" "./thumb/${size}/{}" \;

This didn't work because the thumb directory is initially empty and doesn't have the same directory structure as src.

I tried to look up the man convert but I can't seem to find the option to automatically make the directories on convert. What's an effective way to convert all my images into a thumbnail size in the thumb directory? Do I need pre-create all the sub directories in thumb?


EDIT

I preceded the command above with this:

find ./src -type d -follow -exec mkdir -p "thumb/${size}/{}" \;

But I'm curious if I'd be able to do everything with one command instead of two?

1 Answer 1

1

UNIX philosophy is to have commands, which do one thing and one thing only. Commands that can write to a file instead of stdout are already stretching this rule.

Whether you can do everything in one command depends on you definition. Does this:

find ./src -type f -follow -iname '*.jp*g' -exec /bin/sh -c \
'mkdir -p `dirname "thumb/'${size}'/{}"` &&'\
'convert -resize 150x150x "{}" "./thumb/'${size}'/{}' \;

count as one command or several: find, sh, mkdir, dirname, convert? The line breaks are just for “readability”.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .