A systems administrator is writing a script to analyze the number of files in the directory /opt/application
/home/. Which of the following commands should the administrator use in conjunction with ls -l | to count the
files?
Show answerHide answer
Correct answer: D wc -l
Explanation
ExplanationThe administrator wants to count the number of files listed by:
ls -l
To count lines of output (each file typically appears on one line), the correct command is:
ls -l | wc -l
What wc -l does:
wc = word count utility
-l = counts lines
Each line corresponds to one listed entry, giving the total file count.
β Why the Other Options Are Incorrect
β less
Pager used to scroll output.
Does not count anything.
β tail -f
Continuously monitors file updates.
Used for logs, not counting lines.
β tr -c
Translates or deletes characters.
Not used for counting entries.
π§ Linux+ Exam Tip
Common pipeline pattern:
Goal Command
Count files/output lines wc -l β
Filter text grep
Sort output sort
Remove duplicates uniq
β οΈ Exam note:
ls -l includes a βtotalβ line, so precise counting often uses:
ls -1 | wc -l
But for this question, wc -l is the intended answer.