Using Grep Command [Duplicate]

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.

0

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.

1
Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest