Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have to bit of housekeeping for old backups and have the following code working on sh:

find /home/backups -mtime +30 -type f -exec rm -rf {} \; 

This works fine as know the location/path, so if the path is diff on another machine how can I modify the command to work on all machines?

If I use the command below that will delete all files 30 days old but I'm only looking to clean up these unique set of backup files only:

find . -mtime +3 -exec rm {} ';' 


share|improve this question

migrated from Oct 12 '11 at 13:18

This question came from our site for professional and enthusiast programmers.

maybe you could consider to use a variable for the path? – Kent Oct 12 '11 at 8:00
Consider using -prune or -delete instead of -exec rm -rf - it's usually a much better option, if your find supports it. – GreyCat Oct 12 '11 at 8:57
up vote 3 down vote accepted

I don't know how would you execute the command on all machines, automatically via ssh? or manually?

anyway, if you want to save the effort of typing path, you may consider that on each machine create a variable with same name, e.g. BACKUP_DIR, it saves the path you need to do the cleaning job.

Then, in your find command, don't hardcode any path, but use the variable.

if you do it automatically via ssh, you know the path when you establish the connection. then just add the path in your find.

share|improve this answer
Yep yep this what was thinking just wanted to get second opinion, thanks kent – daverocks Oct 12 '11 at 8:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.