Admin Life Errors, Fixes, and Encounters

3Jan/100

Find a string in a file

How to search for a string in a selection of files (-exec grep ...).

I've used this method a few times to find a file that I created a while back but can't remember the name. But I do remember some of the source code in that file.
NOTE: # is the command line

# find . -exec grep "function getUserIP" '{}' \; -print

// another good example is to only search by file name, in this case, only look at .php files
# find . -name '*.php' -exec grep "function getUserIP" '{}' \; -print

Filed under: commands Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.