0

Is it possible to search within a directory to scan all files for a particular string, then return the file(s) if the string is found?

For example I am looking to try find files where "120854" is found. If we take the below example using a directory called /users/TCP/ that contains two files called File1 and File2.

File1
-----
Product1:432153
Product2:8614
Product3:975

File2
-----
Product76:87
Product324:684
Product965:120854

The expected outcome would return /users/TCP/File2 as "120854" is found on line 3 in that file. Obviously the directory I'm using has thousands of files and therefore wondering if this is possible. Can't find anything online myself

Thanks!

TCP
  • 33
  • 2
  • 8
  • 1
    Possible duplicate ?! https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux – cirosomma Jun 26 '17 at 08:57
  • Possible duplicate of [How do I find all files containing specific text on Linux?](https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux) – RomanPerekhrest Jun 26 '17 at 08:59

1 Answers1

0

grep -Ril "120854" /users/TCP/

-- R stands for recursive.

-- i stands for ignore case (optional in your case).

-- l stands for "show the file name, not the result itself".

-- /users/TCP/ stands for directory you are searching in

TCP
  • 33
  • 2
  • 8