[plug] removing files

James Devenish devenish at guild.uwa.edu.au
Thu Feb 19 19:54:40 WST 2004


In message <1077191254.14715.22.camel at jlmpc>
on Thu, Feb 19, 2004 at 07:47:34PM +0800, Jon Miller wrote:
> I'm thinking along the line of something like the following:
> #1 generate a listing of magic word
> lsting = `grep -r "magic word" ./
> #2 This is where I get lost, I want to delete the contents of the
> listing.  How can I do this?

If the criterion is that the file contains 'magic string', then one
common motif is the following:

grep -lr "magic word" ./ | xargs rm

Caution: if the names of files contain space characters, the above will
not work. You may need to see the xargs man page to work around this.
There are other ways of doing it, but this is the sort of thing for
which xargs was designed.





More information about the plug mailing list