Which ls invocation shows the attributes of a directory entry itself (permissions, owner, size, timestamp) rather than listing its contents?

Difficulty: Easy

Correct Answer: ls -l -d

Explanation:


Introduction / Context:
Sometimes you need metadata about a directory (its mode bits, owner, size on disk, and timestamps) instead of the names it contains. The ls command provides a way to list the directory entry itself, which is essential for permission troubleshooting and scripting around directory attributes.


Given Data / Assumptions:

  • You want details of a directory as an object, not the directory's contents.
  • You are using ls with familiar flags.
  • Standard GNU/BSD ls semantics apply.


Concept / Approach:

The -d option tells ls to list directories themselves, not their contents. Combining with -l (long format) shows permissions, ownership, size, and timestamp. For example, ls -ld /var/log outputs the metadata for /var/log as a single line, rather than enumerating files within it.


Step-by-Step Solution:

Choose -d to avoid descending into directories.Add -l to display detailed attributes.Command: ls -l -d DIRNAME (or ls -ld DIRNAME)Interpret output fields (mode, links, owner, group, size, date, name).


Verification / Alternative check:

Compare ls -l /tmp (lists contents) versus ls -ld /tmp (shows directory entry). The latter confirms the correct behavior.


Why Other Options Are Wrong:

  • ls -l: lists directory contents in long format.
  • ls -x: fills rows across; does not target directory entry.
  • ls -F: appends indicators (/ for directories); does not change listing target.
  • None of the above: incorrect because ls -l -d is correct.


Common Pitfalls:

  • Forgetting -d and getting a long list of contained files instead of the directory's metadata.
  • Confusing directory permissions (execute on directory allows traversal, not execution of files).


Final Answer:

ls -l -d.

Discussion & Comments

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