Monday, September 22, 2014

Manage Files Older than certain days

Today, I found a quite useful trick to list, delete or manage file that is older than certain days
This trick is simple to housekeep and simply check if archiving process is running well day on day basis.

The basic is

find /path/to/files* -mtime +5 -exec command {} \;

You may easily change the command to :

ls -- to list files
rm -- delete
tar -czf -- to create a tar.gz archive

or anything you may try, and let me know the result.

Change the /path/to/files* to exact path you want to check
+5 means older than 5 days. Simply change to let say +30 for files older than 30 days

This should work on any linux. Tested on Ubuntu, CentOS, and RedHat.
Hope this small trick could save your precious working time, and let more time for having fun :)

Cheers