grep -H "string" *
This will print the matching line.
-H is for printing the matching filename.
2. To search for a string/regular expression in all files in a folder + subfolders
grep -H "string" * -r
3. To search for a string in all files of certain type
find . -name "pattern" -exec grep -H "string" {} \;
grep -H "string" $(find . -name "pattern")
Example: To find string "main" in all .c file
find . -name "*.c" -exec grep -H "main" {} \;
grep -H "main" $(find . -name "*.c")
No comments:
Post a Comment