Searching a file with given content recursively in unix

Some time ago I had the problem to search files with a given string in lots and lots of directories with lots and lots of files. Finally I used this command to show me every file in a given directory (plus sub-directories) which contains the search-string.

find . -name "*.php" -print | xargs grep "searchstring"

Means: Search for all php files which contain the string “searchstring”.

Tags: , , , ,

One Response to “Searching a file with given content recursively in unix”

  1. Ole Tange Says:

    Your use of xargs may give surprising results. See here why http://en.wikipedia.org/wiki/Xargs#The_separator_problem

    Consider using GNU Parallel http://www.gnu.org/software/parallel/ instead.

    Watch the intro video to GNU Parallel at http://www.youtube.com/watch?v=OpaiGYxkSuQ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: