Updated: 12 October 2026 · Applies to: GNU findutils 4.9 to 4.10 and GNU coreutils 9.4 to 9.7 (Debian 13, Ubuntu 24.04, AlmaLinux 10); uutils coreutils 0.10.0 (Ubuntu 26.04), tested
To list files by date in one folder, run ls -lt (newest first) or ls -ltr (oldest first). To list and sort files by date in a folder and all its subfolders, use find to print each file's modification time and sort to order the list:
find /srv/site -type f -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r
Drop the -r to put the oldest file first. The dates are printed as year-month-day, so a plain text sort is also a correct date sort.
The examples below are a lab example from a Debian 13 test container with a small website folder. Ubuntu 24.04, AlmaLinux 10 and Ubuntu 26.04 (which uses the Rust uutils versions of ls, sort and stat) gave the same results.
1. List files by date in one folder (ls)
$ ls -lt total 12 -rw-r--r-- 1 root root 0 Oct 11 09:12 index.php -rw-r--r-- 1 root root 0 Oct 10 22:40 style.css drwxr-xr-x 2 root root 4096 Oct 8 10:00 backups drwxr-xr-x 2 root root 4096 Oct 8 10:00 logs drwxr-xr-x 3 root root 4096 Oct 8 10:00 uploads -rw-r--r-- 1 root root 0 Oct 1 12:00 config.php
ls sorts only the folder you point it at. A subfolder is listed with its own date, which changes only when a file is added, removed or renamed directly inside it, not when a file deeper down is edited. Full dates, the -u and -c time options and more are in How to Sort ls Output by Date in Linux: Newest First, Oldest First and Full Dates.
2. List and sort files by date in all subfolders (find and sort)
$ find /srv/site -type f -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r 2026-10-11 09:12 /srv/site/index.php 2026-10-11 08:59 /srv/site/logs/error.log 2026-10-10 22:40 /srv/site/style.css 2026-10-09 02:30 /srv/site/logs/access.log 2026-10-05 10:00 /srv/site/uploads/2026/photo.jpg 2026-10-01 12:00 /srv/site/config.php 2026-09-30 01:00 /srv/site/backups/site-2026-09-30.tar.gz 2026-08-15 10:20 /srv/site/backups/site-2026-08-15.tar.gz 2026-03-02 09:30 /srv/site/uploads/2026/logo.png 2025-12-24 18:05 /srv/site/uploads/old-notes.txt
-type flists files only; use-type dfor folders. Hidden files are included automatically.%Tis the modification time (mtime).%Cgives the status change time (ctime) and%Athe last access time (atime), with the same letters after them.- Add
| head -20for the 20 newest files, or%sfor the size in bytes:-printf '%TY-%Tm-%Td %TH:%TM %8s %p\n'. - For seconds and fractions, use
%T+: it printed2026-10-11+09:12:00.0000000000 /srv/site/index.php.
To get the familiar ls -l columns for the whole tree, let find pass the files to one ls command:
$ find /srv/site -type f -exec ls -lt --time-style=long-iso {} +
-rw-r--r-- 1 root root 0 2026-10-11 09:12 /srv/site/index.php
-rw-r--r-- 1 root root 0 2026-10-11 08:59 /srv/site/logs/error.log
-rw-r--r-- 1 root root 0 2026-10-10 22:40 /srv/site/style.css
(output shortened)
With many thousands of files, find starts ls several times and each batch is sorted on its own, so use the -printf method for large trees.
3. Show only the newest or oldest file
%T@ prints the time as seconds since 1970, which sorts reliably with sort -n. tail -1 keeps the newest file and cut removes the number:
$ find /srv/site -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2- /srv/site/index.php
Use head -1 instead of tail -1 for the oldest file.
4. Find files changed in the last minutes or days
find /srv/site -type f -mmin -60: changed in the last 60 minutes.find /srv/site -type f -mtime -7: changed in the last 7 days (7 times 24 hours).find /srv/site -type f -mtime +30: not changed for more than 30 days.
$ find /srv/site -type f -mtime +30 /srv/site/backups/site-2026-08-15.tar.gz /srv/site/uploads/2026/logo.png /srv/site/uploads/old-notes.txt
find counts whole 24-hour periods and drops the fraction, so -mtime +30 matches files at least 31 full days old. In the test, the backup from 30 September (11 days old) and config.php (10 days old) were correctly left out. Pipe any of these into the -printf ... | sort command from step 2 to see them in date order.
5. Find files modified on a specific date or between two dates
-newermt compares with a date you type. Combine it with ! (not) to set an end date. Files changed on 11 October:
$ find /srv/site -type f -newermt '2026-10-11' ! -newermt '2026-10-12' /srv/site/index.php /srv/site/logs/error.log
Files changed from 1 October up to the end of 7 October, sorted by date:
$ find /srv/site -type f -newermt '2026-10-01' ! -newermt '2026-10-08' -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort 2026-10-01 12:00 /srv/site/config.php 2026-10-05 10:00 /srv/site/uploads/2026/photo.jpg
A date without a time means midnight in the server's time zone. You can add a time, for example -newermt '2026-10-11 08:00'. To list files changed after another file, use -newer: find /srv/site -type f -newer /srv/site/config.php.
6. Sort lines of text by date (sort command)
If you searched for "linux sort by date" to order lines in a log or CSV file, sort needs to know where the date is and what format it has:
- Dates like
2026-10-09(ISO format): a plainsortworks;sort -rputs the newest first. - Dates like
24/12/2025(day/month/year): split on/and sort by year, month, then day. - Syslog lines like
Oct 9 02:30:01:-k1,1Msorts month names in calendar order.
$ sort /tmp/dmy.txt 02/03/2026 logo uploaded 09/10/2026 backup finished 11/10/2026 deploy started 24/12/2025 notes saved $ sort -t/ -k3,3n -k2,2n -k1,1n /tmp/dmy.txt 24/12/2025 notes saved 02/03/2026 logo uploaded 09/10/2026 backup finished 11/10/2026 deploy started $ sort -k1,1M -k2,2n -k3,3 /tmp/syslog.txt Mar 2 09:30:10 vps app[88]: logo uploaded Oct 9 02:30:01 vps CRON[512]: backup finished Oct 11 09:12:44 vps app[90]: deploy started Dec 24 18:05:00 vps app[71]: notes saved
The first command shows the problem: a plain sort put the 2025 line last. The last command shows a limit of the syslog format: it has no year, so the December 2025 line sorts after October 2026. Logs that span a new year are easier to sort when they use ISO dates. You may also see ls -l | sort -k6M -k7n suggested; it sorts by month and day only and ignores the time and year, so ls -lt or the find method is more reliable.
Related articles
- Linux find Command Cheat Sheet for Finding Files
- Linux Text Processing Commands: grep, sort, uniq, wc, cut, tr and diff with Examples
- How to List Files in Linux with the ls Command: Options and Examples
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.
