In Unix/Linux command-line usage, which command is used to list the contents of directories (i.e., show files and subdirectories)?

Difficulty: Easy

Correct Answer: ls

Explanation:


Introduction / Context:
The ability to list files and directories is foundational when working in Unix or Linux shells. Command-line navigation, file management, and scripting all begin with knowing which tool reveals directory contents reliably and flexibly. This question checks recognition of the standard command used across most Unix-like systems to display directory listings.


Given Data / Assumptions:

  • You are in a Unix/Linux shell (e.g., bash, zsh, sh).
  • You want to view files and subdirectories in the current or a specified path.
  • Utilities mentioned include common but different-purpose commands.


Concept / Approach:

The canonical Unix command for listing directory contents is ls. It supports numerous options for formatting (e.g., -l for long listing, -a to include hidden files, -h for human-readable sizes). While other operating systems (such as DOS/Windows) use dir, on Unix/Linux the primary tool is ls. Understanding this distinction prevents cross-platform confusion when switching between shells and terminals.


Step-by-Step Solution:

Identify the operating environment: Unix/Linux.Recall the standard command: ls.Note useful variants: ls -la, ls -lh, ls -R.Select the option that matches the Unix listing command.


Verification / Alternative check:

Running ls prints the names of entries in the working directory. Using ls /etc lists contents of /etc, confirming the command's purpose.


Why Other Options Are Wrong:

  • lp: sends print jobs to the print system; not for listing directories.
  • dir: primarily a DOS/Windows command; on some Unix variants it may exist but is an alias to ls, not the canonical answer.
  • tar: archives files; does not list directory contents by default.
  • None of the above: incorrect because ls is correct.


Common Pitfalls:

  • Confusing Windows' dir with Unix' ls.
  • Forgetting flags to reveal hidden dotfiles (use -a).


Final Answer:

ls.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion