×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Language: Bash
Posted by: Mr. Zick
Added: Jul 18, 2012 4:06 AM
Views: 46
Tags: no tags
Find text inside files GREP
  1. To quickly find any text string within any text file, try this from a terminal window:
  2.  
  3. grep -l  [text to find] [files to look in]
  4.  
  5. For example, grep -l 123abc *.html will list the name of any file in the current directory that ends in .html and contains the string 123abc.
  6.  
  7. (That's a lower-case-L following the GREP)
  8.  
  9. Quite powerful, and fairly fast. Now, if you have some spare time, and want to see what it can really do, try this:
  10. su root
  11. cd /
  12. grep -lr "text to find" *
  13. This will tell the OS to find the "text to find" in every file in every directory, all the way down through the tree. The -r flag tells grep to recursively search directories.
  14.  
  15. Of course, OS X has something like 26,000 files, so this can take a very long time!