BASH script to remove files by time

This script removes every *.wav file older then one minute in the directory it is executed.  This script is very useful and can be used with the cron daemon for regular file removal.

find ./*.wav -type f -mmin +1 -exec rm {} \;

Also we can adjust this for days rather than minutes by changing ‘-mmin +1’ to ‘-mtime +10’.  This would delete .wav files in the working directory that were older than 10 days.

find ./*.wav -type f -mtime +10 -exec rm {} \;

One more example,  the script below will erase all MP3 files older than 10 days form Matt’s music directory.  I hope this is of use to someone out there.

find /home/matt/music/*.mp3 -type f -mtime +10 -exec rm {} \;

Written by mattb in: Linux,Scripts | Tags: , , , , , ,

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment