Scot's Tech Stuff | Scot's Ramblings

grep

Search for a file (based on content/string) recursively and return the file name AND the line of text that contains the string

grep -H -r “string to search for” /

  • “-H” means to return the file name instead of the line of text
  • “-r” means to search recursively
  • “/” is the begining point to search from of “root”

This would give you an output similair to:

filename.txt: string to search for

*******

*******

If you ONLY want the file name you will have to integrate the “cut” command as follows

grep -H -r “string to search for” / | cut -d: -f1


Comments are closed.

Theme Design by devolux.nh2.me