Bird
0
0

A sysadmin wrote the script: for file in /var/log/*; do echo $file; done but it does not list hidden log files. What is the fix?

medium📝 Debug Q6 of 15
Linux CLI - System Administration
A sysadmin wrote the script: for file in /var/log/*; do echo $file; done but it does not list hidden log files. What is the fix?
AAdd <code>ls -a</code> inside the loop
BUse <code>echo $file.*</code> instead
CChange to <code>for file in /var/log/.* /var/log/*; do echo $file; done</code>
DNo fix needed; hidden files cannot be listed
Step-by-Step Solution
Solution:
  1. Step 1: Understand globbing for hidden files

    Globbing * does not match hidden files starting with dot.
  2. Step 2: Fix by including hidden files explicitly

    Adding /var/log/.* includes hidden files in the loop.
  3. Final Answer:

    Change to for file in /var/log/.* /var/log/*; do echo $file; done -> Option C
  4. Quick Check:

    Include hidden files by adding dot-glob [OK]
Quick Trick: Use dot-glob pattern to include hidden files [OK]
Common Mistakes:
  • Adding 'ls -a' inside loop without changing glob
  • Using incorrect echo syntax
  • Believing hidden files can't be listed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes