Difficulty: Easy
Correct Answer: ls -l .lst
Explanation:
Introduction / Context:Command-line globbing patterns are crucial for filtering files by name. In Linux/UNIX shells, the asterisk * and other special characters expand to sets of filenames before the command runs. The ls utility then lists those files. Understanding which pattern truly selects files with a specific extension avoids accidental matches and incorrect outputs.
Given Data / Assumptions:
Concept / Approach:The pattern “.lst” matches any file whose basename ends in the literal characters “.lst”. The ls -l flag produces a long listing. Other patterns here either select different names or are malformed for the stated goal. Therefore, “ls -l *.lst” precisely expresses “detailed listing of all .lst files.”
Step-by-Step Solution:
Identify the extension constraint: must end with “.lst”.Use the wildcard syntax: *.lst to match that suffix.Add -l to request long-format details.Run “ls -l *.lst” in the target directory.Verification / Alternative check:Run “echo *.lst” to see expanded matches. Compare “ls .lst” (short listing) versus “ls -l .lst” (long listing) to verify output differences.
Why Other Options Are Wrong:ls lst: matches names beginning with “lst”, not ending in “.lst”. ls .: matches names with any dot, far broader than “.lst”. ls [lst]: matches names ending in one of the characters l, s, or t, not the string “.lst”. None of the above: incorrect because option A is correct.
Common Pitfalls:Quoting the pattern (e.g., ".lst") prevents shell expansion when not desired; forgetting that hidden files (starting with a dot) are not matched by “” unless your shell option dotglob is set.
Final Answer:ls -l *.lst
Discussion & Comments