As our digital lives become increasingly dynamic, managing files efficiently is crucial. One common task is to find files that have been recently modified to stay on top of changes or track activities.
Whether you are a developer, system administrator, or a regular computer user, knowing how to identify files modified within the last 24 hours can be incredibly valuable.
In this article, we will explore how to achieve this using the powerful find command on Unix-based systems.
Finding Files Modified Within the Last 24 Hours
The find command is a powerful and efficient utility employed to locate files and directories based on various criteria, including modification time, creation time, and access time within your Linux system.
To search for files based on their modification time, the “find” command offers the
"-mtime" option allows us to search for files based on their modification time, which is measured in days.
1. find Command with -mtime Option
To search for all the files in the “Downloads” directory that have been modified/altered exactly 24 hours ago, execute the command below.
$ find ~/Downloads -type f -mtime 0
If you want to search the entire system, you can use the root directory
/, but be aware that this can be time-consuming and may return a vast number of results.
$ find / -type f -mtime 0
If you want to search for files within the current directory and its subdirectories, use the following command.
$ find . -type f -mtime -0
Here is the breakdown of the above command:
-type foption ensures that only regular files (excluding directories and other special files) are included in the search results.
-mtime -0option restricts the search to files modified within the last 24 hours ago.
You can even utilize the value
“-1” for the
“-mtime” flag in the find command to get all the files that are updated within 24 hours.
$ find ~/Downloads -type f -mtime -1
“1” in the above command represents the number of days, while the negative sign indicates “Less Than”. In short, it will search for files modified within the last 24 hours.
2. find Command with -mmin Option
Moving forward, let’s explore another option of the “find” command named
"-mmin" (stands for “Modification Minutes“), which is used to search for files based on their modification time in minutes instead of days.
$ find ~/Downloads -type f -mmin -1440
In the above command, the
"-1440" indicates “less than 1440 minutes,” with the value derived by converting 24 hours into minutes (24 hours * 60 minutes).
3. find Command with -newermt Option
-newermt option is used to find files based on their modification time but unlike the
-mmin options, which allows us to specify an exact date and time rather than a relative time period.
$ find ~/Downloads -type f -newermt "24 hours ago"
While discussing the
"-newermt" flag, let’s delve into another argument, “1 day ago” which serves the purpose of finding files that have been modified within the past day:
$ find ~/Downloads -type f -newermt "1 day ago"
You can also find files modified on a certain date (regardless of the time):
$ find ~/Downloads -type f -newermt "2023-08-05"
4. Using ls and Grep Commands
Lastly, let’s discuss another cool command that combines the “ls” and
"grep" commands to look for files modified within the last 24 hours.
$ ls -lt ~/Downloads | grep 'Jul 21'
Being able to quickly find files that have been modified within the last 24 hours is a valuable skill for anyone working with files on Unix-based systems.
Thanks to the find command and its flexible options that offers a straightforward and efficient way to locate files modified within the last 24 hours.