Find a value or string in all files

| | Comments (1) | TrackBacks (0)

This useful command will find all files where a given string, word, value etc is contained within the file. It will search recursively through all directories from where you are presently within the file system:

find RANGE -iname ‘RULES’ | xargs grep ‘STRING’ -GREP_ARGUMENTS

  • RANGE = where you are searching. Using a . (full stop) will search all from where you presently are
  • RULES = elements of a filename. For instance, ‘*.doc’ will only look through files ending in .doc - * is used as a wildcard
  • STRING = the needle in the haystack that we are looking for

Typical Grep Arguments Used

  • -s is the same as —no-messages. From man grep: “Suppress error messages about nonexistent or unreadable files.”
  • -l, —files-with-matches. From man grep: “Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.” Basically this just outputs the filename.
  • See man grep for more

The Final Result Example (I tend to use this a lot):

find . -iname ‘*php’ | xargs grep ‘needle’ -sl

This looks for the value ‘needle’ in php files only and will only display the file names.

0 TrackBacks

Listed below are links to blogs that reference this entry: Find a value or string in all files.

TrackBack URL for this entry: http://cyberissues.eu/cgi-bin/mt-tb.cgi/17

1 Comments

avehoose Author Profile Page said:

Sands at Superior gold your investment will receive the eye is deserves. Shopping for numismatic cash and gold bullion are commodities that gives you a superb return on your investments do not hesitate to contact a crew of execs that may put you on the road to wealth vacheron constantin replica vacheron constantin replica , wedding dresses wedding dresses Superior Gold group is such a group in place whore prepared sandals fake corum watches fake corum watches fake watches fake watches

Leave a comment

About this Entry

This page contains a single entry by Edward Bellamy published on January 3, 2011 1:50 PM.

Adding a Date to a Tar file in Linux was the previous entry in this blog.

Asterisk Configuration Settings for outgoing calls - UK BT ISDN2e BRI is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

    follow me on Twitter