I have tried to use GREP command but i couldn't figure out exactly how it works. Can someone help be. I want to know how i could use this command to search for the phrase 'Failed password for root' in the auth.log file.
1 Answer
First of all it's grep
- in lower case.
In general man grep
will give you an overview of how grep works. For instance, the first paragraph on usage states
grep [OPTIONS] PATTERN [FILE...]
grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.
PATTERN is what we're looking for, and file is the argument to look trough.
To search for Failed password for root
in /var/log/auth.log
, the command would be
grep "Failed password for root" /var/log/auth.log
The PATTERN has to be quoted, as it contains spaces.
-
2Note: when PATTERN involves special characters like
*
or$
that are also recognized by shell, it's better ro use single quotes or at least backslash escapes Jan 21, 2018 at 22:01