0

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

Thanks.

1
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.

  • 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
0
grep -R

obviously including your search term.

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

0

The shortest possible way: rgrep :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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