Running a command on all file occurences in a directory tree

Chris F.A. Johnson c.f.a.johnson-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org
Fri Oct 8 22:55:22 UTC 2004


On Fri, 8 Oct 2004, Christopher Browne wrote:

>> What I want to do is resize all of the JPGs in a long and ramified
>> directory tree.  I figured something like:
>>
>> find . -name *.jpg
>>
>> in the top of the tree would do the trick for hitting all of the jpgs,
>> but I don't know how to take the output of the above and have it do
>> this:
>>
>> convert $FILENAME -resize 425 $FILENAME
>>
>> Basically, I don't know bash very well and need help with the syntax.
>> Thanks.
>
> There's a way of doing this inside the find command, but I'd suggest the
> following:
>
> for picture in `find . -name *.jpg`; do
>  convert $picture -resize 425 $filename
> done

     This will fail if there are any whitespace or wildcard characters
     in the filenames. It will also overwrite $filename if there is
     more than one .jpg in any directory.

     It would be better if IFS=$'\n', but it's not a good idea to
     iterate over the output of a command in this manner, especially
     when dealing with filenames.

> This makes it easy to extend it to have some meaningful output...
>
> a=1; for picture in `find . -name *.jpg`; do
>  echo "Processing picture $a - $picture"
>  convert $picture -resize 425 $filename
>  ((a++)
> done

-- 
 	Chris F.A. Johnson                      http://cfaj.freeshell.org
 	=================================================================
                 Everything in moderation -- including moderation
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list