How Do You Search a Directory in Linux for Files That Have Content That Match a Pattern?

Problem scenario
Linux novices call directories "folders."  You want to search all the directories and subdirectories for a string pattern.  How do you do this?

Solution
1.  Change directories into the directory where you want to start searching.

2.  Run this command:  grep patterntosearchfor * -ir

Replace "patterntosearchfor" with the pattern you want to find.  Use all lower case.  The "i" flag tells the Linux server to return case-insensitive matches.  The "r" flag tells the Linux server to search subdirectories (child directories) of the directory you were in.

Leave a comment

Your email address will not be published. Required fields are marked *