LinuxMoz

Linux Stuff && Coffee

Recursive Grep Command - Recursively Search Through Directories

| Comments

How to perform a recursive grep on Linux, allowing you to search through files / sub directories for a specific string.

How to grep recursively

1
grep -r SEARCHSTRING /home/*

Enter your own search in the SEARCHSTRING above…

Say for example I am searching for the string class=“author” located somewhere in /var/www/wp-content/themes/your-theme. I would type the following at the shell prompt:

1
grep -r class="author"   /var/www/wp-content/themes/your-theme/*

Grep will then output the string found in the file on the right and the file it’s located in on the left.

Example:

1
2
grep -r sub_rss    theme/*
theme/lib/functions/widgets.php:                   "sub_rss"

Note in the example above I am searching for the string sub_rss in the dir themes.

Comments