Bash – Removing old directories (old backups, log files, etc)

Quick hint on how to remove directories older than N days

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

Given example will remove all subdirectories of directory /backup that are older than 7 days. I use it to remove old backups downloaded from one of my remote servers.

Categories: Hosting, Linux, Software


  1. I belive that log files can be handled by logrotate. I remember that I had problem with big development.log and test.log in Rails projects.

  2. Yes indeed. Log rotate is great – here I was thinking more about an old backups and stuff that might be removed without any harm to our development/monitoring. However you can always combine both solutions :)

Leave a Reply

Your email address will not be published. Required fields are marked *


Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑