Home > Linux > grep all files and sub-directories in a directory for a string

grep all files and sub-directories in a directory for a string

October 14th, 2005 Tony Leave a comment Go to comments

This is mostly just a post for my recollection. To search all files and subdirectories recursively for a phrase:

grep -r -i somethingtosearchfor ./

Categories: Linux Tags:
  1. Scott Wilson
    October 25th, 2005 at 13:36 | #1

    Tony, what’s the difference between -i and -name? I have used the -name switch a lot with success, as in:

    grep ./ -name foo

  2. Tony Spencer
    October 25th, 2005 at 20:26 | #2

    Hey Scott,
    I’m not sure what the difference is. I only pulled this trick out my little reference book.

  3. Anonymous
    November 9th, 2005 at 08:29 | #3

    -i means ignorecase

  4. Tal
    March 11th, 2008 at 11:18 | #4

    Guys,

    Not all Unixes have a “grep” that supports the “-r” option.
    This command is little longer but will work on any unix:

    find top-dir -exec grep whatever /dev/null {} \;