Re: Finding files containing 'string'

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

 



Daniel Vogel wrote:

Give Les the prize:-)


> I had two suggestions:
> 1. gnome-search-tool
> 2. find ./ -name "*" -exec grep "string" {} /dev/null \;
>
> Someone suggested even a better command solution than 2. above but I
> can't remember what it is.
> --

find . -type f -print0 |xargs -0 grep "string"

This selects only files (not symlinks), and copes well wifh path names containing spaces and other difficult characters.

Here are two small improvements:
find . -type f -print0 |xargs -0 --no-run-if-empty grep -H "string"

Otherwise, xargs may run grep with no filename args, and if grep has one filename arg it won't list the file name (the point of using /dev/null in some other examples).

Use of xargs reduces the number of times grep is loaded and run, sometimes an important matter.


should work.


..err...my sugestion is much simple...

grep -e <string> <files>

the for example:
grep -e Daniel *.html

This doesn't descend subdirectories (the point of using -r).

Aa compatibility note. Probably not important to all, but I think recursion is fairly new (say. more recent than RHL 5.x or 6.x) - I don't remember seeing it before and I did look for it, and I'm sure I've asked about it. There may be other greps out there that don't support recursion (or -H for that matter).






--

Cheers
John

-- spambait
1aaaaaaa@xxxxxxxxxxxxxxxxxxxxxxx  Z1aaaaaaa@xxxxxxxxxxxxxxxxxxxxxxx
Tourist pics http://portgeographe.environmentaldisasters.cds.merseine.nu/

do not reply off-list


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux