From: Stefan Walk Date: 2005-12-27T23:47:53+09:00 Subject: Re: Found a neat trick for doing recursive one-liners Pat Maddox wrote: > Or you can use the tools designed for finding stuff :) > > find . -name "*.txt" | xargs grep Hello > > That version will work for all files. You can play with find to match > any file you want. > > Pat > et@adel:/tmp/rb$ touch 'foo bar.txt' et@adel:/tmp/rb$ find . -name "*.txt" ../foo bar.txt et@adel:/tmp/rb$ find . -name "*.txt" | xargs grep Hello grep: ./foo: No such file or directory grep: bar.txt: No such file or directory et@adel:/tmp/rb$ find . -name "*.txt" -print0 | xargs -0 grep Hello et@adel:/tmp/rb$ Watch out if you are using xargs. It can get pretty nasty, especially if there is not grep at work, but rm or alike. Shooting yourself in the foot 101: $ touch "foo .. bar -rf moo.o" $ find . -name '*.o' | xargs rm *BAM* If you are using find and xargs, always use -print0 and -0, respectively. Regards, Stefan