Syntax:
grep <option> "pattern" /path/of /file/to/be/searched
Example:
grep root /etc/passwd – The command searches for the pattern root in the file /etc/passwd and print the lines that matches the pattern.
grep -c /bin/tcsh /etc/passwd - List the number of users who use tcsh
grep -l '^#include' /usr/include/* - List header files that have at least one #include directive
Options:
-c, --count
It prints a count of matching lines for each input file.
-n, --line-number
Print each line of output with the line number within its input
file.
-o, --only-matching
Show only the part of a matching line that matches the pattern.
-R, -r, --recursive
Read all files under each directory, recursively; this is equiv-
alent to the -d recurse option.
No comments:
Post a Comment