Grep – Argument list too long

I ran into this problem the other day and I scratch my head for a long time before I found this solution. I better save this one here for future reference 🙂

I just did a simple operation like this:

grep 123456789 files/*

and this resulted in a “bash: /bin/grep: Argument list too long”. The reason for this is that the files directory contains about 24000 files. This is a little to much for grep to handle like that.

but if you do like this it works (takes quite some time though)

find files/ -type f | xargs grep 123456789
  1. What if I want to look for some files with particular extension?

    $find /dir/ -type f -name *.pub | xargs grep PRIVATE
    -bash: /usr/bin/find: Argument list too long

    • Hi,

      I just tested your command and it seems to work just fine on Red Hat Enterprise Linux AS release 3 (Taroon Update 9) and OSX 10.7.5. Does my original command work on your machine?

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

This site uses Akismet to reduce spam. Learn how your comment data is processed.