In this small series I will introduce Linux shell commands.
Search for a File containing a string in Linux
To find a file containing a certain string in a directory use grep:
To search for a file in all subdirectories containing a certain string recursively add -r:
To search for all occurrences of a string in a file just specify that filename:
To only show file names add -l:
For more useful flags read the grep man pages.
Advanced grep Text Search: Logical Operators and Exclusion of Results
egrep provides more regular expression characters, so we can do a bit more:
It is possible to use the OR logical operator when searching files for text in linux.
To search for a file containing one string OR another string use:
To exclude egrep search results containing a string use: