Re: List files containing a string..
- From: per@xxxxxxxxxxxx (Per Hedeland)
- Date: Sat, 31 Mar 2007 11:32:09 +0000 (UTC)
In article <JFqtMv.12pA@xxxxxxx> bv@xxxxxxx (Bill Vermillion) writes:
In article <Q-6dnWQdVLdGEpDbnZ2dnUVZ_vCknZ2d@xxxxxxxxxxx>,
Max Files <maxfiles@xxxxxxxxx> wrote:
"Per Hedeland" <per@xxxxxxxxxxxx> wrote in message
news:eujsig$18f1$4@xxxxxxxxxxxxxxx
In article <slrnf0q9s0.va.philip+usenet@xxxxxxxxxxxxxxxxxxxx> PhilipI love you man.....
Paeps <philip+usenet@xxxxxxxx> writes:
Geir <geir02@xxxxxxxxx> wrote:
Pardon my ignorance, but if I need to search all files on a disk and
list
the path/name of files containing <string>, how would I do that in
freebsd?
With find(1).
eg: find / -name '*string*'
Er, the question was about files containing a string, not about file
*names* containing a string. And while I basically agree that this
question rather belongs in comp.unix.shell or the like, I think we have
to accept that the concept of "Unix" isn't as clear-cut as it is for us
old-timers - people run FreeBSD or Linux-<mumble>, and if they wonder
about something they (at best) post a question in the group dedicated to
that OS. We do see a lot of non-FreeBSD-specific questions here, and
they mostly get concrete replies, which I think is reasonable. So
finally, the correct reply is:
find / -type f | xargs grep -l string
And anyone who wants to take that as a cue to talk about -print0 is
welcome to do so.:-)
--Per Hedeland
per@xxxxxxxxxxxx
I've been asking this kind of question for a long time. And all I ever
got were responses like man grep, and check out another newsgroup.
I was never aware of the xargs command. At least now I can do a
man xargs and find out more.
What is not readily apparent in the xargs man page is that it
avoids the problems that occur when you use an -exec command in
a find statement and get the error about the list being too large.
Uh, maybe because it doesn't?:-) I.e. there is no such problem since
-exec only ever gets a list of length 1. I guess you're thinking of
grep string `find / -type f`
But actually the xargs man page doesn't say anything about why you'd
want to use it at all:-) - and indeed avoiding the argument length limit
of execve(2) is certainly the main reason.
And it is also more efficient working on many items at once
instead of one at a time when you typically use -exec.
Definitely so, but the `` variant would probably be more efficient still
if it only worked.:-) Hm, well, find | xargs may be "better" due to
making use of parallellism, in particular if the command is
CPU-intensive and/or if you have multiple CPUs, also it may make better
use of file system caching.
And for completeness, I guess it should be mentioned that the GNU grep
that is the standard one on FreeBSD has a -r/-R option and even
--include and --exclude, which means it can subsume some of the
functionality provided by 'find' - the above find | xargs pipeline is
(mostly) functionally equivalent to
grep -lr string /
I don't really "like" that because it's "non-standard", but laziness has
made me use it more and more since all the Unices that I normally use
have GNU grep... Hm, maybe not on '/' though:
grep -lr foo /grep: /dev/network: Permission denied
grep: /dev/geom.ctl: Permission denied
grep: /dev/devctl: Permission denied
grep: /dev/ata: Permission denied
grep: /dev/io: Permission denied
grep: /dev/sysmouse: Permission denied
grep: memory exhausted
Also, it seems grep -r follows symlinks, which you almost never want for
a recursing operation - e.g. 'find' doesn't do that unless you
specifically ask for it, for grep I can't even see a way to turn it off.
--Per Hedeland
per@xxxxxxxxxxxx
.
- References:
- List files containing a string..
- From: Geir
- Re: List files containing a string..
- From: Per Hedeland
- Re: List files containing a string..
- From: Max Files
- Re: List files containing a string..
- From: Bill Vermillion
- List files containing a string..
- Prev by Date: Re: List files containing a string..
- Next by Date: Re: restore subdirectory from dump to new partition
- Previous by thread: Re: List files containing a string..
- Next by thread: How to install a FreeBSD on Intel-based Mac?
- Index(es):
Relevant Pages
|