Updated: 10 October 2026 · Applies to: GNU ls 8.32 (Rocky Linux 9), 9.4 (Ubuntu 24.04), 9.5 (AlmaLinux 10) and 9.7 (Debian 13); uutils ls 0.10.0 (Ubuntu 26.04)
To sort files by date with ls, run ls -lt: -t sorts by last modification time with the newest file first, and -l shows the date and time next to each name. To put the oldest file first (newest at the bottom), add -r: ls -ltr. To see the full date with the year on every line, add --time-style=long-iso.
ls -lt ls -ltr ls -lt --time-style=long-iso
The examples below were run in a test folder on Debian 13. AlmaLinux 10, Rocky Linux 9, Ubuntu 24.04 and Ubuntu 26.04 (which uses the Rust uutils version of ls) gave the same results with the same options.
1. Sort by date, newest first
$ ls -lt total 12 -rw-r--r-- 1 root root 0 Oct 9 08:15 index.php -rw-r--r-- 1 root root 0 Oct 8 22:40 style.css drwxr-xr-x 2 root root 4096 Oct 7 03:00 logs drwxr-xr-x 2 root root 4096 Oct 5 10:00 uploads -rw-r--r-- 1 root root 0 Oct 1 12:00 config.php drwxr-xr-x 2 root root 4096 Sep 30 01:00 backups -rw-r--r-- 1 root root 0 Mar 2 2026 readme.txt -rw-r--r-- 1 root root 0 Dec 24 2025 old-notes.txt
The time shown is the modification time (mtime): when the file's content was last changed. For a directory it is the last time a file was added, removed or renamed inside it. Files with exactly the same time are listed by name. ls --sort=time is the long form of -t.
Notice that two lines show a year instead of a time. ls shows the time only for files changed in the last six months; older files get the year. Section 3 shows how to get the full date on every line.
2. Sort by date, oldest first
$ ls -ltr total 12 -rw-r--r-- 1 root root 0 Dec 24 2025 old-notes.txt -rw-r--r-- 1 root root 0 Mar 2 2026 readme.txt drwxr-xr-x 2 root root 4096 Sep 30 01:00 backups -rw-r--r-- 1 root root 0 Oct 1 12:00 config.php drwxr-xr-x 2 root root 4096 Oct 5 10:00 uploads drwxr-xr-x 2 root root 4096 Oct 7 03:00 logs -rw-r--r-- 1 root root 0 Oct 8 22:40 style.css -rw-r--r-- 1 root root 0 Oct 9 08:15 index.php
ls -ltr is the usual choice in a log folder such as /var/log: the files that changed last end up just above your prompt, so you do not have to scroll. Add -h (ls -ltrh) for sizes in K, M and G.
3. Show the full date and time (ls with date)
- Full date and time in minutes, the same format on every line:
$ ls -lt --time-style=long-iso total 12 -rw-r--r-- 1 root root 0 2026-10-09 08:15 index.php -rw-r--r-- 1 root root 0 2026-10-08 22:40 style.css drwxr-xr-x 2 root root 4096 2026-10-07 03:00 logs ... -rw-r--r-- 1 root root 0 2026-03-02 09:30 readme.txt -rw-r--r-- 1 root root 0 2025-12-24 18:05 old-notes.txt
(output shortened) - Seconds, fractions of a second and the time zone offset:
$ ls -l --full-time index.php -rw-r--r-- 1 root root 0 2026-10-09 08:15:00.000000000 +0000 index.php
--full-timeis the same as-l --time-style=full-iso. - Your own format, using the same codes as the
datecommand:$ ls -lt --time-style=+'%d-%m-%Y %H:%M' | head -3 total 12 -rw-r--r-- 1 root root 0 09-10-2026 08:15 index.php -rw-r--r-- 1 root root 0 08-10-2026 22:40 style.css
- To make a format the default, set the
TIME_STYLEvariable, for example addexport TIME_STYLE=long-isoto~/.bashrc. Then a plainls -ltshows full dates.
Times are shown in the server's time zone. To read them in another zone, set TZ for that one command. On Rocky Linux 9, a file changed at 09:30 UTC showed as 15:00 in India time:
$ TZ=Asia/Kolkata ls -l --time-style=long-iso readme.txt -rw-r--r-- 1 root root 0 2026-03-02 15:00 readme.txt
This needs the time zone data (package tzdata); minimal container images may not have it, and then ls silently stays on UTC.
4. Show only the newest or oldest files
$ ls -t | head -1 index.php
ls -t | head -1: the name of the newest file, handy in scripts.ls -lt | head -6: the five newest entries (the first line istotal).ls -ltr | head -6: the five oldest.ls -lt *.txt: only names that match a pattern, newest first.ls -ltd */: only the directories, newest first.ls -lt --group-directories-firstlists directories first, then files, each group sorted by date.
Parsing ls output in scripts breaks on names with spaces or newlines. For anything more than a quick check, use find, as in section 6.
5. Sort by access time, change time or creation time
Linux keeps several timestamps per file. --time (or a short option) picks which one ls shows and sorts by:
ls -ltu: last access (atime), newest first.ls -ltc: last status change (ctime): content, permissions, owner or name changed.ls -lt --time=birth: creation (birth) time, where the file system records it.stat FILEshows all four times, with creation asBirth.
Keep the -t. According to ls --help, -u and -c with -l but without -t show the other time but still sort by name. Access times are also not updated on every read on most servers (the default relatime mount option), so treat atime as approximate.
Copying a file gives the copy a new modification time. In our test, cp readme.txt copy1.txt produced a file dated today, while cp -p kept the original date:
$ ls -lt --time-style=long-iso total 0 -rw-r--r-- 1 root root 0 2026-10-09 18:24 copy1.txt -rw-r--r-- 1 root root 0 2026-03-02 09:30 copy2.txt -rw-r--r-- 1 root root 0 2026-03-02 09:30 readme.txt
Use cp -p, rsync -a or tar when the dates must survive a copy or a migration.
6. Sort files in subdirectories too
ls -ltR lists every subdirectory, but sorts each folder on its own, so it cannot show the newest file in the whole tree. Use find with sort for that:
$ find . -type f -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r | head -5 2026-10-09 08:15 ./index.php 2026-10-09 07:59 ./logs/error.log 2026-10-08 22:40 ./style.css 2026-10-07 02:30 ./logs/access.log 2026-10-01 12:00 ./config.php
More ways to find files changed in the last few minutes or days are in find and sort files by modification date. For the other ls options (hidden files, sizes, the long listing columns), see how to list files with the ls command, and for patterns such as *.txt, Linux wildcards and globbing.
Ucartz services for this topic
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
