Re: recursive shell commands, is there a simple one?

From: Chris Mattern (syscjm_at_gwu.edu)
Date: 07/16/03


Date: Tue, 15 Jul 2003 19:52:36 -0400

Conrad Whelan wrote:
> hello,
>
> I am interested in running the same command on a number of files in a
> directory tree.

Without even going further--you want find, probably hooked up with xargs.

> Some of the directories in the tree contain other
> directories, while some are, of course, 'leaf' nodes that contains the
> files I wish to modify. I already have a script which can modify the
> approriate file.
>
> I could write a script that would do something like this, but it seems
> like such a plausible operation, that I was thinking there could be a
> standard unix command to do it. If anyone knows of one, I'd be happy to
> hear it (my unix power tools book doesn't have one). If not, a short
> script that anyone has that does this might be helpful too. I am using
> BASH.
>

find /root/of/tree/dir -type f | xargs myscript

If myscript can't take multiple filenames at once, use "xargs -n 1".

This will run myscript on every file (but not the directories) in the
tree. find has many other predicates that you can use to precisely
define what pathnames you want it to retrieve. If you could give
specification, somebody here could probably tell you how to do it.
Or you could read find's man page for yourself.

             Chris Mattern



Relevant Pages