Today I would like to tell you how to search for files by date, which is very useful skill when you spend most of your time on the command-line.
Use the find
utility to search for files modified or created since particular date, but remember that provided datetime will be compared using greater-than sign.
The following example will illustrate basic command usage as it will not match file created/modified at 2015-01-27 00:00:00
, but at least 2015-01-27 00:00:01
.
$ find ~/Documents/ -type f -newermt "2015-01-27"
You can be more precise in this matter and narrow down time interval.
$ find ~/Photos/ -type f -newermt "2015-01-27 12:00" -not -newermt "2015-01-27 13:15"
You are not limited to the strict dates as you can use date
command to ease things a bit.
$ find ~/Projects/ -newermt $(date +'%Y-%m-%d %H:%M' -d 'last Tue 13:00')
The same rules apply if want to search by metadata modification time, which will allow you find files with modified contents or metadata like owner, permissions.
$ find ~/Backups/ -newerct $(date +'%Y-%m-%d' -d 'yesterday')
Everything is described in the find
manual page, so please read it for yourself to get more detail.