[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: running a command on many files in many subdirectories



On Tue, 2003-01-28 at 23:56, Levi Waldron wrote:
> I'm sure this is simple, but maybe someone here can help me do it in a few 
> minutes instead of hours.  I have a bunch of files in a bunch of 
> directories, and I want to run the same command on each of them.  For each 
> input file, the output file should have the same name except ending in .txt, 
> and the output files should be put a common directory.  ie,

Here is something I wrote to do batch Imagemagick conversion on a whole
tree of image while taking advantage of multiple processors if
available. Maybe some of the techniques used could be transposed in your
context.

files=`find . -name '*.tif' -print | wc -l | tail -c 2 | head -c 1`
cpu=`grep processor /proc/cpuinfo | wc -l | tail -c 2 | head -c 1`
nnumber=`expr $files / $cpu`
find . -name '*.tif' -print | sed -e 's/ /\\ /g' | sed -e 's/(/\\(/g' |
sed -e 's/)/\\)/g' | xargs -P $cpu -n $nnumber mogrify -format png


Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: