Linux find last modified file in directory recursively
This post shows you how to list most recent modified files in Linux using linux command ls
and find
command.
List most recent modified files using command ls(not recursive)
If you only want to know which files was last modified in specific directory without traversing sub directories , you can use command:
ls -alrt
-a
means list all files include hidden files-l
means in long format-r
means revere order while sorting modified time-t
sort by modification time,newest first
For example:
j@ubuntu:~$ ls -alrt
total 76
drwxr-xr-x 3 root root 4096 May 7 22:26 ..
-rw-r--r-- 1 j j 807 May 7 22:26 .profile
-rw-r--r-- 1 j j 3771 May 7 22:26 .bashrc
-rw-r--r-- 1 j j 220 May 7 22:26 .bash_logout
drwxr-xr-x 3 j j 4096 May 7 22:38 .local
-rw-r--r-- 1 j j 0 May 7 22:39 .sudo_as_admin_successful
drwxr-xr-x 11 j j 4096 May 7 22:39 .cache
drwxr-xr-x 11 j j 4096 May 7 22:42 .config
-rw------- 1 j j 11 May 7 22:42 .bash_history
drwxr-xr-x 15 j j 4096 Aug 3 19:38 .
drwxrwxr-x 2 j j 4096 Aug 3 19:39 tmp
List last modified file recursively using command find
If you need to do this traversing directories , you can use find
command.
Method 1 : use find command with option -mtime
or -mmin
find -mtime -3 # list files modified in last 3 days
find -mtime -3 -mtime +1 # newer than 3 days and older than 1 day
find -mmin -30 #list files modified in last 30 minutes
find -min -30 -min +15 #newer than last 30 min but older than last 15 min
See Linux Find Cheatsheet and Linux find command examples for more usages and examples
Also see mtime vs ctime vs atime to know the what’s ctime
Method 2 : using find command with option newerXY
-newerXY reference
Succeeds if timestamp X of the file being considered is newer than timestamp
Y of the file reference. The letters X and Y can be any of the following
letters:
a The access time of the file reference
B The birth time of the file reference
c The inode status change time of reference
m The modification time of the file reference
t reference is interpreted directly as a time
For example:
#list files modified between 2021-01-01 00:00 and 2021-01-10 00:00
find . -newermt "2021-01-01" ! -newermt "2021-01-10"
Or specify Date more precise with hour/minute
#list files newer than 2021-08-03 19:40
find -newermt "2021-08-03 19:40"