newbie: to pipe the result of a program as commandlineparameter for another.

Richard Coleman richardcoleman at
Sat Nov 22 09:43:14 PST 2003

Zhang Weiwu wrote:

> Hello. I just checkouted a big program. What I want to do is to remove 
> all CVS/ folders from the hierarchy.
> There might be other ways to do so (give me a hint?). What I can think 
> of is to run find(1) to find out all CVS folders, and pass them as 
> parameters of rm(1), but I don't know how to do so.

That's the purpose of the "xargs" command.  For instance, if you wanted 
to recursively delete all files in the directory /home/foo ending in 
".o", you could use the command

find /home/foo -name '*.o' -print | xargs rm -f

Of course, people will point out that find has options that will allow 
it to remove files directly.  But using xargs is a more general 
technique that will work in other situations.

For instance, if you wanted to "touch" all your *.c files so that they 
have current modification times, you could use the following

find /home/foo -name '*.c' -print | xargs touch

Also, xargs knows about the maximum size allowable for the command line, 
and will use the minimum number of process invocations necessary.

Richard Coleman
richardcoleman at

More information about the freebsd-questions mailing list