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'?
✗ Incorrect
grep dog pets.txt searches for 'dog' in the file 'pets.txt'.
How do you make
grep ignore uppercase or lowercase differences?✗ Incorrect
The -i option makes grep ignore case differences.
What does
grep -c error logfile.txt do?✗ Incorrect
-c counts how many lines contain the pattern.
Which option lets
grep search inside all files in folders and subfolders?✗ Incorrect
-r means recursive search through directories.
What does
grep -v apple fruits.txt do?✗ Incorrect
-v shows lines that do NOT match the pattern.
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.