Bird
0
0

You wrote a script to read a file using head -5 file.txt but it always shows the whole file. What is the likely error?

medium📝 Debug Q14 of 15
Linux CLI - Viewing and Editing Files
You wrote a script to read a file using head -5 file.txt but it always shows the whole file. What is the likely error?
AThe file is empty, so head shows whole file.
BUsing <code>head 5 file.txt</code> without the dash causes the issue.
Chead command does not support line limits.
DThe file has less than 5 lines, so head shows all lines.
Step-by-Step Solution
Solution:
  1. Step 1: Check command syntax

    head requires dash before number, e.g., -5, otherwise it ignores argument.
  2. Step 2: Understand effect of missing dash

    Without dash, head treats '5' as filename, so shows whole file.txt content.
  3. Final Answer:

    Using head 5 file.txt without the dash causes the issue. -> Option B
  4. Quick Check:

    Dash before number is required = B [OK]
Quick Trick: Always use dash before number in head command [OK]
Common Mistakes:
  • Omitting dash before number
  • Assuming head shows whole file always
  • Confusing empty file with command error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes