Which Linux command option is commonly used with ls to display files sorted by…
2024
Which Linux command option is commonly used with ls to display files sorted by their last modified time?
- A.
ls -a - B.
ls -l - C.
ls -r - D.
ls -t - E.
ls -s
Attempted by 5 students.
Show answer & explanation
Correct answer: D
Concept
The ls command lists directory contents in alphabetical order by default. Its sorting behaviour is changed by option flags: each flag selects a different sort key (name, size, or a timestamp). The flag that selects the file's modification timestamp as the sort key is the one that orders output by when each file's contents were last changed.
Applying it here
The option that sorts by last-modified time is ls -t. It uses each file's modification time (mtime) as the sort key and lists the most recently modified file first. So to see files ordered by their last modified time, ls -t is the correct choice (often combined with -l as ls -lt to also show the timestamps).
Why the other flags do not sort by modification time
-aincludes hidden files (those whose names begin with a dot); it does not change the sort order from the default alphabetical.-lswitches to the long listing format (permissions, owner, size, timestamp, name) but still sorts alphabetically by name unless a sort flag is added.-rreverses whatever ordering is currently in effect; on its own it just reverses the default alphabetical order rather than sorting by time.-sprints each file's allocated block size and, with a sort flag, can sort by size, but by itself it does not order files by modification time.
Only the modification-time sort key produces a listing ordered by when files were last changed, which is exactly what the question asks for.