Grep Command Flashcards
What is the grep command?
global regular expression print – picks the strings or pattern from the text of a file or output of a command
What is the basic difference between the "grep" and "find" commands?
grep finds the pattern or strings in data, find is used to find files and directories.
How can I find the pattern/string "root" from the /etc/passwd file?
grep root /etc/passwd
How can you find the patterns/strings "root|failed" in the "/var/log/secure" file?
egrep
“root|failed” /var/log/secure
How can we extract all the lines that contain the word "error|ERROR" in "/var/log/messages"?
grep -i error /var/log/messages or egrep “error|ERROR” /var/log/messages
How can we obtain logs that pertain to "sshd" from the Security logs?
grep sshd /var/log/secure
Use grep and search for the string "usb" from the file that contains hardware messages?
grep usb
/var/log/dmesg
How can we find all the lines in "/etc/passwd" that do not contain the string "root"?
grep -v root
/etc/passwd
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.
grep -o Robert file.txt | wc - l
Which flag would you use to ignore case sensitivity while you grep a pattern?
-i to ignore case
sensitivity