Blogs on System Administration, Scripting, System Monitoring, Cloud Computing & Virtualizaton, VoIP Systems, SMS Systems and Web Applications Development.

How to recursively find and delete files from Server after certain time?


Introduction

You don’t have to write a comprehensive script to handle it but it can be done with just single command:
find /path/to/folder -type f -name "" -mtime + -exec {} \;
For example, we need to remove voicemail messages after 30 days from Asterisk or FreeSwitch Server.

Asterisk

find /var/spool/asterisk/voicemail -type f -name "msg*" -mtime +30 -exec ls -lhtr {} \;
Removing all voicemail messages that exists in server for more than 30 days:
find /var/spool/asterisk/voicemail -type f -name "msg*" -mtime +30 -exec rm {} \;

FreeSwitch

Listing all voicemail messages that exists in server for more than 30 days:
find /usr/local/freeswitch/storage/voicemail -type f -name "msg_*" -mtime +30 -exec ls -lhtr {} \;
Removing all voicemail messages that exists in server for more than 30 days:
find /usr/local/freeswitch/storage/voicemail -type f -name "msg_*" -mtime +30 -exec rm {} \;

It can be added in crontab to execute above command after every 24 hours:
0 0 * * *

0 comments:

Post a Comment

Please Enter your Comments Here.