Find the files that have been changed in last 24 hours
E.g., a MySQL server is running on my Ubuntu machine. Some data has been changed during the last 24 hours.
What (Linux) scripts can find the files that have been changed during the last 24 hours?
Please list the file names, file sizes, and modified time.
6 Answers 6
To find all files modified in the last 24 hours (last full day) in a particular specific directory and its sub-directories:
Should be to your liking
The — before 1 is important — it means anything changed one day or less ago. A + before 1 would instead mean anything changed at least one day ago, while having nothing before the 1 would have meant it was changed exacted one day ago, no more, no less.
You can do that with
[The] time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.
Another, more humane way:
On GNU-compatible systems (i.e. Linux):
This will list files and directories that have been modified in the last 24 hours ( -mtime 0 ). It will list them with the last modified time in a format that is both sortable and human-readable ( %T+ ), followed by the file size ( %s ), followed by the full filename ( %p ), each separated by tabs ( \t ).
2>/dev/null throws away any stderr output, so that error messages don’t muddy the waters; sort -r sorts the results by most recently modified first; and | more lists one page of results at a time.
For others who land here in the future (including myself), add a -name option to find specific file types, for instance: find /var -name «*.php» -mtime -1 -ls
This command worked for me
Not the answer you’re looking for? Browse other questions tagged linux bash find or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2020.9.18.37632
Find Files That Have Been Modified Recently in Linux
Last modified: August 13, 2020
1. Introduction
There are various occasions when we want to search for files that have been changed recently.
For example, as a system admin, we’re responsible to maintain and configure computer systems. Sometimes, because we’re dealing with a lot of configuration files, we probably want to know what are the files recently modified.
In this tutorial, we’re going to find the files that have been changed recently in Linux using bash commands.
2. The find Command
First, we’ll explore the find utility which is the most common way to achieve the intended purpose. This command is used to find files and directories recursively and to execute further operations on them.
2.1. -mtime and -mmin
-mtime is handy, for example, if we want to find all the files from the current directory that have changed in the last 24 hours:
Note that the . is used to refer to the current directory. -mtime n is an expression that finds the files and directories that have been modified exactly n days ago.
In addition, the expression can be used in two other ways:
- -mtime +n = finds the files and directories modified more than n days ago
- -mtime -n = finds the files and directories modified less than n days ago
In the same way, we can use the -mmin n expression to rely on minutes instead of days:
So, this command recursively finds all the files and directories from the /home/sports directory modified at least 120 minutes ago.
Next, if we want to limit the searching only to files, excluding directories, we need to add the -type f expression:
Furthermore, we can even compose expressions. So, let’s find the files that have been changed less than 120 minutes ago and more than 60 minutes ago:
2.2. -newermt
There are times when we want to find the files that were modified based on a particular date. In order to fulfill this requirement, we have to explore another parameter, which has the following syntax:
By using this expression, we can get the files that have been changed earlier than the specified date.
So, let’s build a command to better understand the new parameter:
Moreover, we could get the files modified on a specific date by using a composed expression.
So, we’re going to get the files modified on ‘2019-07-24’:
Finally, there’s another version of the -newermt parameter similar to -mmin and -mtime.
The first command finds the files modified in the last 24 hours. The rest of them are similar:
3. The ls Command
We know that the ls command lists information about the files in a specific directory. One of its usages is to show the long format of the files and to sort the output by modification time:
Which would result in something like:
We may not be able to list the files recently modified exactly as the find command does. But, we can filter the above output based on a specific date or time by applying the grep command on the result of the ls command:
Note that the find command is recursive by default. In order to enable the recursive capability on the ls command, we also need to add the R(uppercase) parameter:
4. Conclusion
In this quick tutorial, we’ve described a few ways that help us find the files that have been changed recently on a Linux operating system.
First, we’ve explored the find command and created several examples with different parameters like -mtime, -mmin and -newermt.
Then, we’ve shown how we can achieve similar results using a combination of two better known Linux utilities like the ls and grep commands.
How to Find Recently Modified Files/Folders in Linux
by Magesh Maruthamuthu · Last Updated: September 23, 2019
If you are using the Linux system for daily operation, your home directory files will increase dramatically over time.
If you want to find a directory size in Linux, check out the following article
If you have thousands of files, you can’t remember the file name you recently changed.
Also, if you want to check the list of files created or modified or accessed for any purpose.
This article will help you to meet your need.
How does it work, and on what basis do we decide?
In Linux, each file contains three timestamps that are updated when the file is modified or replaced.
A file in Linux contains three timestamps:
- atime: access time or Last access time
- mtime: modify time or Last modification time
- ctime: change time or Last change time
If you want to know more about this, read the explanation below.
- atime/amin: The last time the file was accessed by some command or application.
- mtime/mmin: The last time the file’s contents was modified.
- ctime/cmin: The last time the file’s attribute was modified.
How do we check all timestamps of a file?
It can be easily saw with stat command. It show you all the timestamps of a file.
The common syntax is as follows:
How to use numerical arguments in this example. If you use “-mtime n”. This returns a list of files that was last modified 24 hours ago.
- +n: for greater than n
- -n: for less than n
- n: for exactly n
See the format below for a better understanding.
- -mtime +10: Use this format, if you want to find a file that was modified 10 days ago.
- -mtime -10: Use this format, if you want to find a file that was modified less than 10 days.
- -mtime 10: Use this format, if you want to find a file that was modified exactly 10 days ago.
1) How to Sort Files and Folders in Reverse Order Based on its Conversion Time
This can be achieved simply by using the ls command.
It sorts files and folders in reverse order based on conversion time.
2) How to Sort Only Folders in Reverse Order Based on File Conversion Time
If you want to sort only folders in reverse order based on the conversion time, use the below command.
3) How to Find Only Files That were Modified 120 Days Ago
The below find command will show a list of files that were changed 120 days ago.
4) How to Find Only Files That was Modified Less Than 15 Days
The below find command will show a list of files that have changed within 15 days.
5) How to Find Only Files That were Modified Exactly 10 Days Ago
The below find command will show you a list of files that were changed exactly 10 days ago.
6) How to Find Only Files That Was Modified Less Than 30 Mins
The below find command will show a list of files that have changed within 30 mins.
7) How to Find Modified Folder in Less Than 5 Days
This command displays only folders modified within 5 days.
8) How to Find Files and Folders That Was Modified in Less Than 15 Days
This command displays a list of files and folders modified within 15 days.
9) How to Find Modified Files and Folders Starting from a Given Date to the Latest Date
This command allows you to find a list of files and folders that have been modified starting from a given date to the latest date.
10) How to Find All Files and Folders Modified in The Last 24 Hours
Alternatively, you can use an easy-to-understand format like the one below to find files and folders that have been changed over the past 24 hours.
11) How to Find a List of “sh” Extension Files Accessed in the Last 30 Days
This command helps you to find a list of files with “sh” extension accessed in the last 30 days.
12) How to Find Files That Have Been Modified Over a Period of Time
The below command shows a list of files that have changed in the last 20 minutes.
13) How to Find a List of Files Created Today
This command enables you to find a list of files created today.