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? Peter
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
On Thursday 02 March 2006 20: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?
Peter
I'm not expert on the CLI but I think: grep -R "a1aaaa" "/tmp/*" Would do it. The '*' expands into a list of all the files and makes for a loooong string.
Bruce, On Thursday 02 March 2006 17:14, Bruce Marshall wrote:
On Thursday 02 March 2006 20: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
...
Peter
I'm not expert on the CLI but I think:
grep -R "a1aaaa" "/tmp/*"
Would do it. The '*' expands into a list of all the files and makes for a loooong string.
Nope. All that does is keep grep from operating recursively, but that's moot because it never gets invoked. The argument list for this invocation is precisely the same as that in the original form tried by the OP. Randall Schulz
On Thursday 02 March 2006 20: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
Googled "grep argument list too long", opened the third hit and followed the first link: http://www.gnu.org/software/coreutils/faq/#Argument-list-too-long regards, Carl
Carl, Peter, On Thursday 02 March 2006 17:15, Carl Hartung wrote:
On Thursday 02 March 2006 20: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
Googled "grep argument list too long", opened the third hit and followed the first link:
http://www.gnu.org/software/coreutils/faq/#Argument-list-too-long
Note the use of find's "-print0" option and the corresponding "-0" option to xargs. This will allow this idiom to work even when file names have spaces in them.
regards,
Carl
Randall Schulz
participants (4)
-
Bruce Marshall
-
Carl Hartung
-
Peter Sutter
-
Randall R Schulz