Linux: find recently updated files
I want to share with you one of the useful oneliners I’m using to find recently updated files on our Linux machines. Let’s start simple:
find . -mtime -1 -type f
What do we have here? We are looking for the files only (“-type f”) modified within 24 hours (“-mtime -1”). You can extend the time frame by changing the number, so “-mtime -30” will display all files changed within 30 days.
This is already handy, but how to sort the results by the date changed? We can ask “find” to display modification time and once we will have this information, we can sort it by this time:
find . -mtime -1 -type f -printf "%T@ %p\n" | sort -n
So, now we asked “find” to display the file modification time in Unix Epoch format “%T@” followed with the file name and a new line “%p\n”. The output of the find is sorted using numeric sort (“sort -n”). The newest files will be placed at the end of the list.
If you want to see something more user-friendly than Unix Epoch, you can ask “find” to display year, month, day, hour, minute, and second (please, use this order in order for sort to work properly):
find . -mtime -1 -type f -printf "%TY-%Tm-%Td.%TH:%TM:%TS %p\n" | sort -n