betweenGo

Shell Tricks

by on Aug.26, 2005, under Miscellaneous

To search for all files that contain a certain string use find with the -exec flag. For example:

find . -name "*.haystack" -type f -exec grep -l needle "{}" ";"

grep -l flag tells grep to output only the file name if there is a match.
"{}" is replaced iteratively by the file names found.
";" terminates the command.


Share

Related posts:

  1. Save the Output in a Shell Script Variable
  2. Unable to start Cygwin shell from Windows command prompt
  3. Save the Output in a Shell Script Array
  4. Perforce Adding a Directory Tree
  5. Maven Assembly Convert Shell Scripts to use UNIX LF’s


1 Comment for this entry

Leave a Reply

 

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!