-->

How to grep a String Recursively in All Files

How do a search string recursively in the file system with grep command? 
Linux grep command is a frequently used command by most of the Linux users. Using grep you can search any string in all files available in the directory hierarchy. You will get come examples of grep command to search any string recursively in the file system.
Grep command uses following syntax to search pattern Recursively in all files available under specific directory and its sub directories.
$ grep -R "search-pattern" /path/to/search/dir

Search Pattern Recursively in Files:

Search for pattern “example.com” in all files available under /var/www/html directory.
$ grep -R "example.com" /var/www/html

Search Pattern Recursively in Specific Extension Files:

Make your search more specific, like search a string “example.com” in all files with the extension .php only. To achieve this use --include option to force grep to search for the specific file only and ignore others.
$ grep -R --include="*.php" "example.com" /var/www/html
You may also specify multiple file extensions to search
$ grep -R --include="*.php" --include="*.conf" "example.com" /var/www/html

No comments:

Post a Comment