Delete files by age on Linux

Share:  facebook  twitter  reddit  digg  stumble  

Often it might be necessary to remove files older than a certain age on a Linux machine. This uses the bash programming language which is native to most Linux distributions. It can be run on a regular basis by scheduling it with the crontab, or run once to clean out old files. The time variable can be changed to suit the user's needs, more examples can be found at the Save Lono software engineering help site.

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.

More Information
provided by

DateAugust 14, 2009