Re: OT: running a command on many files in many subdirectories
On Tue 28 Jan 2003 17:56:51 +0000(-0500), 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,
>
> java ImageInfo dir1/pic1.jpg > commondir/pic1.txt
>
> etc, repeated over a bunch or directories and jpg files. The subdirectories
> only go one deep.
Try this:
for f in */*.jpg ;do java ImageInfo $f > commondir/`basename $f .jpg`.txt ;done
If there are too many files for the command line then replace "for f in */*.jpg" with
find . -maxdepth 2 -name \*.jpg | while read f
> If this is difficult I could copy all the jpg files into a single
> directory first with only a little bit of tedium.
No need for that.
I hope this helps.
--
Cheers,
Clive
Reply to: