RE: About grep

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> >
> > My personal favorite is still:
> >
> >   find . -type f -exec grep 'abc' {} /dev/null \;
> >
> Why not just:
> grep -rn "abc" .
>
> Prints filenames and linenumbers, searches recursively (starting with
> ".", the current directory).
>

"find" can give you more refined control over the files you are looking for.
In John's example, he is only grepping on regular files (text files)
with -type f.  Your example would also grep binary files which is something
you may not want to do.  If you don't care running both, I'd combine them

find . -type f -print | xargs grep -n "abc"

I also like this becuase occasionally I also want to use -C NUM with grep
(shows NUM lines before and after the matching line)

find . -type f -print | xargs grep -n -C 3 "abc"



-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux