How to Check a File’s Modification Date on Linux Using Four Simple Commands
This guide explains four practical Linux commands—stat, stat with a custom format, date with the -r option, and ls -lt—to display a file’s last modification timestamp, and also shows how to retrieve remote file dates using the httpie tool.
Overview
When you need to know when a file was last edited on a Linux system, several built‑in commands can provide the modification timestamp. This article presents four local methods and one remote method using httpie.
1. Using stat
The stat command displays detailed file attributes, including access, modify, and change times. Run it with the file name:
[root@localhost ~]# stat hello_script.sh
File: ‘hello_script.sh’
Size: 31 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 67169379 Links: 1
Access: (0755/-rwxr-xr-x) Uid: (0/ root) Gid: (0/ root)
Access: 2020-10-15 19:13:24.628009932 +0800
Modify: 2020-10-15 19:07:18.266426499 +0800
Change: 2020-10-15 19:11:48.227856412 +0800
Birth: -The Modify line shows the last modification date and time.
2. Using stat -c %y for a concise output
To display only the modification timestamp, use the custom format option -c %y:
[root@localhost ~]# stat -c %y hello_script.sh
2020-10-15 19:07:18.266426499 +08003. Using date -r
The date command normally shows the current date, but with the -r flag it reports the modification time of a given file:
[root@localhost ~]# date -r hello_script.sh
Thu Oct 15 19:07:18 CST 20204. Using ls -lt to sort by modification time
The long‑list format ls -l can be combined with -t to order entries by their modification timestamps, showing the most recent files first:
[root@localhost ~]# ls -lt
# or
[root@localhost ~]# ll -tThe output lists files with their permissions, owners, sizes, and the modification date column.
5. Checking remote file dates with httpie
httpieis an HTTP client that can retrieve HTTP headers. After installing it (e.g., yum install python-pip && pip install httpie or apt install httpie), you can request the Last-Modified header of a remote resource:
http -h https://www.example.com/file.png | grep -i 'Last-Modified'Example output:
Last-Modified: Fri, 05 Jun 2020 14:26:11 GMTConclusion
By using stat, stat -c %y, date -r, ls -lt, or the httpie tool, you can quickly obtain the modification date of local files or remote resources on a Linux system.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
