Syntax:
Grep command uses following syntax to search pattern Recursively in all files available under specific directory and its sub directories.
Search Pattern Recursively in Files
For example, you want to search a string “Hello” in all files available under /var/www directory. Also search the files under subdirectories of parent directory. This will traverse the directory tree under /var/www and print all files including line content containing string “Hello”. The above command will search for case sensitive string only. You can also search for strings matching in any case. This will all string in any case like “hello”, “HELLO” or HeLLo” etc.
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. You may also specify multiple file extensions to search
Conclusion
In this tutorial, you have learned to search a string in all files under a directory tree on Linux.