Grep Command Flashcards

1
Q

What is the grep command?

A

global regular expression print – picks the strings or pattern from the text of a file or output of a command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the basic difference between the "grep" and "find" commands?

A

grep finds the pattern or strings in data, find is used to find files and directories.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can I find the pattern/string "root" from the /etc/passwd file?

A

grep root /etc/passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you find the patterns/strings "root|failed" in the "/var/log/secure" file?

A

egrep
“root|failed” /var/log/secure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can we extract all the lines that contain the word "error|ERROR" in "/var/log/messages"?

A

grep -i error /var/log/messages or egrep “error|ERROR” /var/log/messages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can we obtain logs that pertain to "sshd" from the Security logs?

A

grep sshd /var/log/secure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Use grep and search for the string "usb" from the file that contains hardware messages?

A

grep usb
/var/log/dmesg

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can we find all the lines in "/etc/passwd" that do not contain the string "root"?

A

grep -v root
/etc/passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can I determine the number of occurrences of the string "Robert" in a text file using the command line? Please provide the necessary command to achieve this.

A

grep -o Robert file.txt | wc - l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which flag would you use to ignore case sensitivity while you grep a pattern?

A

-i to ignore case
sensitivity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly