Re: [nottingham] Recursively act on a certain filetype?

From: Graeme Fowler (graeme@graemef.net)
Date: Tue 30 Jul 2002 - 09:16:15 BST


On Tue, 30 Jul 2002, Paul Sladen wrote:
[snip brief 'find' explanation]
> The `xargs' program takes the contents of stdin (data `piped' to it) and put
> them on the command line, eg:
[snip]
> $ find ./ -name '*.o' | xargs rm

Or you could just make use of the -exec switch to find, which allows
clever things like:

[root]# find /usr/src/widget/ -name \*.c -exec rm -f {} \; -name \*.o
-exec mv {} /usr/src/widget-objects/

...and (this may vary from distro to distro) Paul missed the "-i" and "{}"
from xargs, too:

$ find ./ -name '*.o' | xargs rm

becomes

$ find ./ -name '*.o' | xargs -i rm {}

and if you want to see what's being done:

$ find ./ -name '*.o' | xargs -i -t rm {}

Here endeth the "101 ways to skin a cat" lesson :)

G

--------------------------------------------------------------------
http://www.lug.org.uk http://www.linuxportal.co.uk
http://www.linuxjob.co.uk http://www.linuxshop.co.uk
--------------------------------------------------------------------



This archive was generated by hypermail 2.1.3 : Tue 30 Jul 2002 - 09:16:35 BST