Linux: find files by date range


By modification time:

find /path/to/find -newermt "TIMESTART" -not -newermt "TIMEEND"

Example:

find /home -newermt "2020-06-14 00:00:00" -not -newermt "2020-06-15 00:00:00"

By access time:

find /path/to/find -newerat "TIMESTART" -not -newerat "TIMEEND"

By change time:

find /path/to/find -newerct "TIMESTART" -not -newerct "TIMEEND"

Example: delete all mp4 files with access time older than 7 days:

a=$(date -d "7 days ago" "+%Y-%m-%d %H:%M:%S") && find /some/folder -iname "*.mp4" -not -newerat "$a"| xargs rm -f

Note: You can use more humane ways:

find /path -newermt "-24 hours"

find /path -newermt "1 day ago"

find /path -newermt "yesterday"

Leave a Reply