0
0
Linux CLIscripting~5 mins

grep (search text patterns) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the grep command do in Linux?

grep searches for text patterns in files or input and shows the matching lines.

Click to reveal answer
beginner
How do you search for the word apple in a file named fruits.txt using grep?

Use grep apple fruits.txt. This shows all lines containing apple in the file.

Click to reveal answer
beginner
What option do you add to grep to ignore case when searching?

Use -i option. For example, grep -i apple fruits.txt finds apple, Apple, or APPLE.

Click to reveal answer
intermediate
How can you count the number of matching lines with grep?

Use the -c option. For example, grep -c apple fruits.txt shows how many lines contain apple.

Click to reveal answer
intermediate
What does the -r option do in grep?

-r makes grep search recursively inside all files in a directory and its subdirectories.

Click to reveal answer
Which command finds lines containing 'dog' in the file 'pets.txt'?
Agrep -r dog
Bgrep pets.txt dog
Cgrep dog pets.txt
Dgrep -c dog pets.txt
How do you make grep ignore uppercase or lowercase differences?
A-i
B-c
C-v
D-r
What does grep -c error logfile.txt do?
ACounts lines with 'error'
BShows lines with 'error'
CSearches recursively for 'error'
DIgnores lines with 'error'
Which option lets grep search inside all files in folders and subfolders?
A-i
B-r
C-c
D-v
What does grep -v apple fruits.txt do?
AShows lines with 'apple'
BSearches recursively for 'apple'
CCounts lines with 'apple'
DShows lines without 'apple'
Explain how to use grep to find a word in a file and ignore case differences.
Think about the option that ignores uppercase and lowercase.
You got /4 concepts.
    Describe how to count the number of lines that match a pattern using grep.
    Look for the option that counts matches.
    You got /5 concepts.