grep command form (syntax)
grep “text string to search” directory-path or ip addtressExamples
For example search for a string called redeem reward in all text files located in /home/guest/*.txt directory, use$ grep "192.168.xx.xx" /home/guest/*.txtTask: Search all subdirectories recursively
You can search for a text string all files under each directory, recursively with -roption:$ grep -r "192.168.xx.xx" /home/guestTask: Only print filenames
By default, grep command prints the matching lines You can pass -H option to print the filename for each match.$ grep -H -r “192.168.xx.xx” /home/guestOutput:
... filename.txt: 192.168.xx.xx ...To just print the filename use cut command as follows:
$ grep -H vivek /etc/* -R | cut -d: -f1Output:
No comments:
Post a Comment