Mailing List Archive

Support open source code!

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

Re: grep resistance

Tony Laszlo wrote:
> It is apparently not possible to grep
> through a directory which has a large
> number of files (perhaps the limit
> is someone near 1,000 or so).
> I happen to have a directory which has
> more than 10,000 files and found
> that grep gives the error
> "Argument list too long."

Are you sure it's a grep problem? 
Sounds like a shell problem to me. 
I doubt that there is a limit on number of files
but there is a limit on command line length.

> Here is a workaround which works
> pretty well:
> find . -type f -exec grep -n -C STRING '{}' ';' | less
> problem is, it doesn't display the name of the
> file. Can this be adjusted to do so?
Another solution:
find . -type f -exec grep -n -C STRING '{}' /dev/null ';' | less

(Adding /dev/null to list of files is an old
 trick to make sure grep prints the file name
 even if there is only one file. Useful for

The best solution I can come up with is:
ls -1 | xargs grep ..... /dev/null | less

/Fredric Fredricson

(Btw. Wouldn't fgrep be faster?)

Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links