We received a tip from blog readers Christian and Michael for alternatives to the command to delete all directories older than a certain period of time. These both work in bash and can be used in scripts to clean up old backup directories or any situation where you need to delete old directories from the command line.

From Christian:

find /home/backup/ -maxdepth 1 -type d -mtime +7 -exec rm -r {} \;

From Michael:

find /home/backup/ -maxdepth 1 -type d -mtime +7 -exec echo “Removing Directory => {}” \; -exec rm -rf “{}” \;

The first one works quietly, while the second one will display what is being deleted. These are probably faster than putting it into a for loop, so feel free to use whatever works best in your particular situation!

You May Also Like

Block brute force password attempts via SSH

If you are a system administrator of a linux system, you may…

PHP Script for controlling APC PDU via SNMP

This one is neat – you can control those APC PDU Power…

Greasemonkey + Duggmirror Script = Awesome

Don’t you hate it when you try to visit a digg story…

Remove Duplicate Email Messages in Thunderbird 2.x

I used to use a Thunderbird addon to remove duplicate messages in…