On Unix/Linux command lines, which command is typically used to list the contents of directories (filenames, optionally with details)?
-
Atar
-
Bdir
-
Clp
-
Dls
-
ENone of the above
Answer
Correct Answer: ls
Explanation
Introduction / Context:Listing files is one of the most common terminal tasks. On Unix-like systems, the standard tool for enumerating directory contents is distinct from the commands used on DOS/Windows, so it is important for cross-platform users to recognize the correct utility and common flags.
Given Data / Assumptions:
- We are on a Unix/Linux shell.
- We want to see directory contents, optionally with long format, hidden files, or sorting.
- Coreutils are installed.
Concept / Approach:
The ls command lists files and directories. Common options include -l (long format), -a (include hidden files), and -t (sort by modification time). While some systems alias dir to ls, ls is the canonical Unix command.
Step-by-Step Solution:
Basic listing: lsDetailed listing: ls -lShow hidden files: ls -laNewest first: ls -ltVerification / Alternative check:
Use type ls or which ls to confirm the binary. Explore man ls for exhaustive options.
Why Other Options Are Wrong:
- tar: archiving tool, not directory listing (though it can list archive contents).
- dir: DOS command; on Unix it may be an alias but ls is standard.
- lp: print submission in System V printing.
- None: incorrect because ls is correct.
Common Pitfalls:
- Forgetting that globs expand before ls runs, affecting results.
- Confusing hidden file handling; add -a to include dotfiles.
Final Answer:
ls.