Find String In Files With Grep
Posted:
Monday, November 21st, 2011Last modified:
Thursday, April 9th, 2015How to find all instances of a given string in multiple files with grep.
Basic Usage
This example uses the Drupal Zen theme's STARTERKIT directory.
grep "background-color" css/*.css
Returns something like:
css/block-editing.css: background-color: #fff; css/comments.css: /* background-color: #fff4f4; */ css/comments.css: /* background-color: #ffffea; */ css/drupal6-reference.css: background-color: #ff6; css/drupal6-reference.css: background-color: #ffd; css/drupal6-reference.css: background-color: #fff4f4; css/drupal6-reference.css: background-color: #ffffea; css/drupal6-reference.css: background-color: #fff4f4; css/drupal6-reference.css: background-color: #ffffea; css/drupal6-reference.css: background-color: #ddd; css/drupal6-reference.css: background-color: #000; [... and so on...]
Recursive Usage
grep -r "background-color: #ff6;" themes
Returns something like:
themes/subtheme/css/drupal6-reference.css: background-color: #ff6; themes/zen/STARTERKIT/css/drupal6-reference.css: background-color: #ff6;
Available Wiki Topics
The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.