Bird
0
0

You run locate *.log but get no results, even though you know log files exist. What is the likely problem?

medium📝 Debug Q14 of 15
Linux CLI - Searching and Finding
You run locate *.log but get no results, even though you know log files exist. What is the likely problem?
AThe locate database is corrupted and needs repair
BThe locate command does not support wildcards
CThe shell expands *.log before locate runs, causing no matches
DYou need to run locate with sudo to see log files
Step-by-Step Solution
Solution:
  1. Step 1: Understand shell wildcard expansion

    When you run locate *.log, the shell tries to expand *.log to matching files in the current directory before running locate.
  2. Step 2: Effect on locate command

    If the current directory contains *.log files, the shell expands to those specific names (e.g., locate error.log access.log), so locate searches only for exact matches to those names system-wide, missing other .log files and causing incomplete or no results. The correct way is to quote the pattern: locate '*.log'.
  3. Final Answer:

    The shell expands *.log before locate runs, causing no matches -> Option C
  4. Quick Check:

    Quote wildcards to prevent shell expansion [OK]
Quick Trick: Quote wildcards to avoid shell expansion [OK]
Common Mistakes:
  • Assuming locate can't use wildcards
  • Thinking database corruption causes no results
  • Believing sudo is needed for locate

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes