Search This Blog

Monday, July 12, 2010

find a file with specific string inside it

This is very useful command especially when you need to find a file with specific string inside it.

I normally use this command to find out my script which was misplaced in file system.


grep -r 'text to search for' /path/to/dir

Below command is not checked but seems to be working.
reference:
grep -oHnr "some pattern" *.txt
-o print Only the matched parts of a matching line, with each part on a separate line. -H print the filename for each match.
-n prefix each line of output with the 1 based line number.
-R, -r recursively read all files under subdirectories.

1 comment:

  1. Nice Blog. specially for students & Beginners. Add some Topic for Professionals.

    ReplyDelete