[LINK] Big patch for big hole in Google Desktop

Craig Sanders cas at taz.net.au
Thu Feb 22 13:03:25 AEDT 2007


On Thu, Feb 22, 2007 at 12:27:08PM +1100, Howard Lowndes wrote:
> Craig Sanders wrote:
> >On Thu, Feb 22, 2007 at 11:39:48AM +1100, Howard Lowndes wrote:
> >>I have two excellent tools for searching my PC - "find" and "grep" - who 
> >>needs more?
> >
> >locate is useful.  and so is xargs (both are part of gnu findutils).
> >
> >i use xargs probably several times every day.
> >
> >e.g. to grep for "WHATEVER" in all files under DIR:
> >
> >	find DIR -type f -print0 | xargs -0 grep WHATEVER
> 
> grep -irl WHATEVER /path/to/start/*

that's useful for a Q&D search, but not as flexible, for several reasons:

1. you can fine-tune find's search criteria - select by timestamp,
owner, permissions, file type, (partial or full) filename, mod time,
access time, etc etc.

2. you can pipe the list of files output by find through sed or grep or
awk or whatever before piping it into xargs.

3. it's a generic solution to a whole lot of tasks, xargs can run any
command you want on the list of files you give it.

once you get in the habit of it, it becomes second nature to just think of
building a list of files (by whatever means is most convenient for the job at
hand) and pipe that list into xargs so that it can run whatever command you
want on each of them.

e.g. to delete all files under DIR containing the string "FOOBAR":

    find DIR -type f -print0 | xargs -0 grep -Zl FOOBAR | xargs -0 rm -f 

craig

-- 
craig sanders <cas at taz.net.au>



More information about the Link mailing list