Linux ls Command Sort by Time: Full Guide
In this article
The ls command in Linux sorts files by time using the -t option (newest first) or -tr (oldest first). You can also use --time-style to control how timestamps are displayed, and --sort=time as an explicit alternative to -t.
How the Time Sort Works
By default, ls sorts entries alphabetically by name. When you add -t, it reorders the output by modification time (mtime) — the last time the file's content was changed. The newest file appears first. The -l flag (long format) is commonly combined with -t to show the timestamp alongside each file, making the order visible.
Example:
ls -lt
This lists files with details, newest first. To reverse the order (oldest first), add -r:
ls -ltr
Many admins use ls -ltr to see the most recently modified files at the bottom of the output, which is handy when the directory has many entries.
Sorting by Access or Change Time
Linux tracks three timestamps per file:
- mtime — modification time (content changed)
- atime — access time (file was read)
- ctime — change time (metadata changed, e.g., permissions or rename)
To sort by atime, use -u with -t:
ls -ltu
To sort by ctime, use -c with -t:
ls -ltc
Note that -u and -c also affect which timestamp is displayed in the long format. Without them, ls -l shows mtime.
Choosing Which Time to Display
The --time option gives more explicit control. For example:
ls -l --time=atime
This shows access time in the listing. Similarly, --time=ctime shows change time. When combined with -t, it sorts by that same timestamp.
Controlling the Time Format
By default, ls -l shows a short date like “Jun 12 10:30” for files modified within the last six months, and a year for older files. To get a full timestamp, use --time-style. Common styles include:
--time-style=long-iso→2025-06-12 10:30:45--time-style=full-iso→2025-06-12 10:30:45.123456789 +0000--time-style=+%Y-%m-%d %H:%M→ custom format usingdatesyntax
Example:
ls -l --time-style=long-iso -t
This gives a clean, sortable timestamp and sorts by mtime.
Sorting by Time in Reverse and with Other Options
You can combine time sorting with other ls options. For instance, to show all files (including hidden) sorted by modification time:
ls -lat
To show directories first, then sort by time within each group:
ls -lt --group-directories-first
To sort by time but ignore backup files (~ or #), use -B:
ls -ltB
Common Pitfalls and Misconceptions
One frequent mistake is assuming -t sorts by creation time. Linux does not store a creation time in the traditional ext4 filesystem (though some filesystems like btrfs do, and stat may show it). The ls command has no option to sort by birth time in most versions. If you need creation time, you must use stat or a filesystem-specific tool.
Another issue: ls -t sorts only by mtime, not by the time shown in the long listing if you also use -u or -c. Always check which timestamp you are sorting by.
Also, ls does not sort recursively by default. To sort files in subdirectories by time, you need find or ls -R (which does not sort globally). For a recursive time-sorted list, use:
find . -type f -printf '%T@ %p\n' | sort -n
Frequently Asked Questions
How do I sort by time in reverse order?
Use ls -ltr. The -r reverses the sort order, so the oldest files appear first and the newest last. This is useful when you want to see the most recent files at the bottom of a long list.
What is the difference between mtime, atime, and ctime?
mtime is the last time the file content was modified. atime is the last time the file was read. ctime is the last time the file's metadata changed, such as permissions or renaming. Note that ctime updates whenever mtime updates, because changing content also updates metadata.
Can I sort by file size instead of time?
Yes, use -S to sort by file size, largest first. Combine with -r for smallest first. Example: ls -lS.
Why does ls -t not show the files in the order I expected?
Check whether you are looking at the correct timestamp. By default, -t sorts by mtime. If you used -u or -c, it sorts by atime or ctime. Also, if you have many files with the same timestamp, the order among them may be alphabetical.
How do I see the exact time in ls -l output?
Use --time-style=long-iso or --time-style=full-iso. For example: ls -l --time-style=long-iso. You can also define a custom format like --time-style=+%Y-%m-%d %H:%M:%S.
Does ls -t work on directories?
Yes, it sorts the listed entries (files and directories) by their modification time. To sort directories by their own mtime, the same option applies. If you want to list only directories, use -d */ or find . -maxdepth 1 -type d.