Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question
up vote 1 down vote accepted
grep -rl "string" /path


  • -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


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.