[NBLUG/talk] bash shell commands

Andru Luvisi luvisi at andru.sonoma.edu
Tue Sep 2 17:22:00 PDT 2003


On Tue, 2 Sep 2003, Jeremy Turner wrote:
[snip]
> Another way to skin a cat:
>
> find ./dir -type f -print -exec grep 'something' \{\}\;
>
> Notice the -exec flag and the escaped {}; (necessary for the find
> command).

This will spawn a new grep process for each file.  The xargs way will
batch them into fewer runs of grep, so it will normally run faster.

Another tip:

Since grep will print out filenames if it has more than one argument, here
is a way to make sure it always shows a filename, even if find only finds
one file:
  find ./dir -type f -print |xargs grep 'stuff' /dev/null

grep won't find anything in /dev/null, but having it there will make sure
that grep prints out the filename.  For example:

 luvisi at gladen:~$ grep root /etc/group
 root:*:0:
 luvisi at gladen:~$ grep root /dev/null /etc/group
 /etc/group:root:*:0:
 luvisi at gladen:~$

Andru
-- 
Andru Luvisi

Quote Of The Moment:
  Great spirits have always encountered violent opposition from
  mediocre minds.
                  -- Albert Einstein
  
  They laughed at Einstein.  They laughed at the Wright Brothers.
  But they also laughed at Bozo the Clown.
                  -- Carl Sagan




More information about the talk mailing list