Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I use grep to search subdirectories as well as the files in the current directory?

Thanks.

share|improve this question

3 Answers 3

up vote 1 down vote accepted
grep -rl "string" /path

Where:

  • -r (or --recursive) option is used to traverse also all sub-directories of /path, whereas
  • -l (or --files-with-matches) option is used to only print filenames of matching files, and not the matching lines (this could also improve the speed, given that grep stop reading a file at first match with this option).

For more informations, see man grep.

share|improve this answer
    
For future readers: many command line programs, apart from grep, also support the option "work with all sub-files and sub-folders", and that option is nearly-always called --recursive or -r or -R. –  Li-aung Yip Oct 23 '13 at 7:40
grep -R

obviously including your search term.

I can highly recommend reading grep's man-page. man grep

share|improve this answer

The shortest possible way: rgrep :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.