Bird
0
0

Given a directory with files containing the word 'apple' in some files, what will be the output of grep -r 'apple' ./fruits?

medium📝 Command Output Q4 of 15
Linux CLI - Searching and Finding
Given a directory with files containing the word 'apple' in some files, what will be the output of grep -r 'apple' ./fruits?
AOnly file names containing 'apple' in ./fruits
BList of all lines containing 'apple' from all files in ./fruits and subfolders
CCount of files containing 'apple' in ./fruits
DNo output unless combined with -l option
Step-by-Step Solution
Solution:
  1. Step 1: Understand grep -r output behavior

    By default, grep -r prints matching lines with file names.
  2. Step 2: Apply to given command

    grep -r 'apple' ./fruits prints all lines containing 'apple' from all files recursively.
  3. Final Answer:

    List of all lines containing 'apple' from all files in ./fruits and subfolders -> Option B
  4. Quick Check:

    Default grep -r output = A [OK]
Quick Trick: grep -r shows matching lines, not just file names [OK]
Common Mistakes:
  • Thinking grep -r only lists file names
  • Confusing with -l option for file names only
  • Expecting count without -c option

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes