Bird
0
0

You want to find all lines containing 'error' in .log files recursively but exclude directories named 'backup' and 'temp'. Which command achieves this?

hard📝 Application Q8 of 15
Linux CLI - Searching and Finding
You want to find all lines containing 'error' in .log files recursively but exclude directories named 'backup' and 'temp'. Which command achieves this?
Agrep -r --include='*.log' --exclude-dir={backup,temp} 'error' .
Bgrep -r --include='*.log' --exclude-dir backup,temp 'error' .
Cgrep -r --include='*.log' --exclude backup,temp 'error' .
Dgrep -r --include='*.log' --exclude-dir='backup temp' 'error' .
Step-by-Step Solution
Solution:
  1. Step 1: Use --include to filter .log files

    The --include='*.log' limits search to .log files.
  2. Step 2: Use --exclude-dir with brace expansion

    To exclude multiple directories, use --exclude-dir={backup,temp}.
  3. Step 3: Combine options correctly

    Command grep -r --include='*.log' --exclude-dir={backup,temp} 'error' . does the job.
  4. Final Answer:

    grep -r --include='*.log' --exclude-dir={backup,temp} 'error' . -> Option A
  5. Quick Check:

    Multiple dir exclude uses braces = B [OK]
Quick Trick: Use braces {} to exclude multiple directories [OK]
Common Mistakes:
  • Separating directories with commas without braces
  • Using --exclude instead of --exclude-dir
  • Putting directory names in quotes as one string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes