How to delete files older than certain number of days

One thing that comes very handy is usage of cron to make scheduled job to delete old files so that you can free up some space on your hard drive

# Delete Apache logs older than 60 days
find /var/log/apache2/ -mtime +60 -exec rm {} \;

With this simple script you will search through Apache logs in folder /var/log/apache2, select the ones with access time older than +60 (60 days) and execute delete with rm command.

 

 

MySQL purge old binary logs

If mysql-bin.xxxyyy logs are eating up your partition space. This is the right trick for you:

# login to mysql
mysql -u root -p
# create latest log mysql-bin.0000xy
flush logs;
# purge all logs before mysql-bin.0000xy
purge binary logs to 'mysql-bin.0000xy';