Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

How to find and delete older files (older than 7 days) in a folder using a bash script? It's a folder in a server which contain automatic backups. Need to delete old ones automatically so there's space for new ones.

share|improve this question
up vote 0 down vote accepted
ssh user@machine "find /path/to/files/ -mtime +7 -exec rm {} \;"

name the script as and give execute permissions.

 chmod +x

Run it as ./ or bash

share|improve this answer
Perfect... thanks :) – THpubs Nov 14 '12 at 9:12

Using the below command, first confirm the file list:

find . -mtime +7

If the list is correct, using below the files can be deleted.

find . -mtime +7 -exec rm '{}' \;
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.