How to Delete Files Older Than a Week in a Folder in Linux

By | July 28, 2010

Sometimes you need to delete some archive files, that are older than the specified date. It’s simple enough in Linux. Here is the command that allows you to do this:

find /path/to/folder/* -mtime +7 -exec rm {} ;

Please, note, that you need to keep spaces between command arguments.

This command is suitable for folders that contain a large number of files. In order to force file deletion you need to add -f key.

find /path/to/folder/* -mtime +7 -exec rm -f {} ;

If you need to move these files instead of deletion, here is the solution:

find /path/to/folder/* -mtime +7 -exec mv {} /path/test-mv-to/ ;

Hope this helps you to deal with archive files and big folders.