Peter, On Thursday 02 March 2006 17:03, Peter Sutter wrote:
I am trying to use grep/egrep to find a file in the /tmp directory. All I get back is
~# grep -R "a1aaaa" /tmp/* -bash: /usr/bin/grep: Argument list too long
Admittedly, there are numerous files in /tmp, how do I get around this limitation in grep?
for a in /tmp/*; do grep "a1aaaa" $a;
done seems to work for one directory only, but I feel this method to be clumsy as it does not give me recursion into subdirectories. Any way to do it directly with grep/egrep?
You can still give the -R option. Grep processes this itself, and won't have problems with diretories that contain too many files to fit into a single argument list. Another thing to keep in mind is that by using "/tmp/*" you have 5 redundant characters, "/tmp/" at the beginning of each argument. By changing directory to /tmp first and just using * you'll save 5 characters per argument (the limit is on the total number of bytes in the argument list). However, the usual and general way to deal with situations like this one is to use the "xargs" command, whose sole puprose is to split up invocations with very large argument lists. In your case, this is what you'd do: % find /tmp -type f |xargs egrep "a2aaaa" $sa As usual, "man xargs" for all the details.
Peter
Randall Schulz