Which ls option lists files ordered by modification time (most recent first) in the current directory?

Difficulty: Easy

Correct Answer: ls -t

Explanation:


Introduction / Context:
Sorting by modification time is a frequent need when investigating logs, build artifacts, or recent changes. The ls command provides a flag to order entries by their last modification time so the newest items appear first, improving situational awareness on busy systems.


Given Data / Assumptions:

  • Standard GNU/BSD ls behavior is available.
  • You want chronological sorting by modification time.
  • No recursion or inode listing is required.


Concept / Approach:

Use ls -t to sort by modification time descending (newest first). Combine with -l for detailed listings or -r to reverse the sort (oldest first). For human-readable timestamps and sizes, add -h where supported.


Step-by-Step Solution:

List newest first: ls -tDetailed newest first: ls -ltOldest first: ls -ltrAcross subdirectories: find . -type f -printf '%T@ %p\n' | sort -n (advanced).


Verification / Alternative check:

Compare output of ls -t with stat for specific files to confirm ordering by modification time (mtime).


Why Other Options Are Wrong:

  • ls -1: one entry per line; not a time sort.
  • ls -i: shows inode numbers.
  • ls -R: recursive listing; no time ordering implied.
  • None of the above: incorrect because -t is correct.


Common Pitfalls:

  • Confusing access time (atime) or change time (ctime) with modification time (mtime).
  • Forgetting -r reverses the order.


Final Answer:

ls -t.

Discussion & Comments

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