Tuesday 22 January 2019

Find and move files older than 365 days in Linux


How to find and move files older than 365 days in Linux

The command:

find /sourcedirectory -iname “*file extension or part of file name*” -mtime +365 -type f -exec mv "{}" /destination/directory/ \;


The mtime command can be modified to another number which will move anything from that number of days and older. The + can also be changed to a - which will move anything newer instead. If neither a + or a - is specified then it will move just files exactly that many days old.

The '-type f' command ensures only files are moved, not directories