Ubuntu users can use find command with -mtime option to find files that have been modified in last 24 hours. The find command is used to locate files and directories based on various criteria.
Using find Command
The ‘find’ command searches the directory tree rooted at each file name FILE by evaluating the EXPRESSION provided. This list of files to search is followed by a list of expressions
describing the files we wish to search for.
find [path] -type f -mmin n
NOTE: The n indicates the time in minutes – how many minutes you want to find files for. The following command options are used:
- -n will find the files which have been modified in less than n minutes (- is for more/decreasing order)
- +n will find the files which have been modified in more than n minutes (+ is for more/increasing order)
- n will find the files which have been modified in exacly specific n minutes
Using Find Command
Find for all the files in the “Downloads” directory that have been modified/altered exactly 24 hours ago:
$ find ~/Downloads -type f -mtime 0
Search the entire system for files which have been modified/altered exactly 24 hours ago:
$ find / -type f -mtime 0
Search for files within the current directory and its subdirectories. It will show the files that have been modified/altered exactly 24 hours ago:
$ find . -type f -mtime -0
Finding files modified in the last 10 minutes
The following fin command will find all the files that have been modified in the last ten minutes. Note that unless path is specified, it will find files in the current directory.
$ find . -type f -mmin -10
Finding files modified in the last n days
You can use -mtime instead of -mmin to find modified files in the last n days instead of n minutes.
For example, to find files that have been modified in the last 3 day in Downloads folder, the following command will be used:
find /Downloads -type f -mtime -3 -ls
Similarly, if you want to find modified directories in the last n minutes or days, just change -type f with -type d. The d is for directories whereas the f is for files.
- Using find Command with -mmin Option
How to Find Files That Have Been Modified in Last 24 Hours
For example to find the files modified in less than 24 hours, we shall use 1440 minutes (24 hours into minutes 24 hours * 60 minutes). See the command given below:
$ find ~/Downloads -type f -mmin -1440
The another way to find files modified within the specific date is by using the find command with -newermt Option
The -newermt option is used to find files based on an exact date and time rather than a relative time period.
The following command can be used to find files modified 24 hours ago:
$ find ~/Downloads -type f -newermt "24 hours ago"