How to move files based on specific time criteria

Use find utility to move files based on specific time criteria.

Find files with modification time older than 4 years inside archives directory and move these files to /mnt/backup/archive/ location preserving directory structure, so the file _posts/2014/11/25/how-to-create-simple-bar-charts-in-terminal-using-awk.html will be moved to /mnt/backup/archive/_posts/2014/11/25/how-to-create-simple-bar-charts-in-terminal-using-awk.html.

$ destination="/mnt/backup/archive/" find archives/ -type f -not -newermt "$(date +'%Y-%m-%d %H:%M' -d "4 years ago")" -exec bash -c 'dirname=$(dirname {}); mkdir -p "${destination}/${dirname}"; echo mv {} ${destination}/${dirname}/' \;

Find files with access time between 2017-01-01 00:00 and 2018-01-01 00:000 inside archives directory and move these files to /mnt/backup/archive/ location preserving directory structure.

$ destination="/mnt/backup/archive/" find archives/ -type f -newerat "2017-01-01 00:00" -not -newerat "2018-01-01 00:00" -exec bash -c 'dirname=$(dirname {}); mkdir -p "${destination}/${dirname}"; echo mv {} ${destination}/${dirname}/' \;

Find files with change time at least 2 days ago inside archives directory descending between two and three levels of directories below the starting-point and move these files to /mnt/backup/archive/ location preserving directory structure.

$ find archives/ -type f -newerct "$(date +'%Y-%m-%d 00:00' -d "2 days ago")"  -exec bash -c 'destination="/mnt/backup/archive/"; dirname=$(dirname {}); mkdir -p "${destination}/${dirname}"; echo mv {} ${destination}/${dirname}/' \;

What is a difference between access, modification and change time?

Access time is the last access timestamp changed when file is accessed.

Modification time is the last modification timestamp changed when file contents are altered. Notice, that access and change time will also be updated. Directory modification time will change when you alter its contents by creating or deleting files, but it is slightly more complicated.

Change time is the last status change timestamp changed when inode information is updated.

Read inode(7) manual page for more information.

Additional information

You can measure times using simpler parameters like -amin, -atime, -mmin, -mtime and -daystart, but I am used to the -newer.. test.