Crazy Basketball Shot
Saturday, August 19th, 2006Not in the textbook of plays or shots…
Not in the textbook of plays or shots…
Having setup a backup server for work and home, I was looking into how to remove archives that were a week or older. Initially, I wrote a simple script to search a path for files that matched a naming convention and whose creation dates exceeded the week limit. This was fine and dandy but not the most elegant and didn’t really increase my linux-fu. So I decided to delve deeper and find a good one-liner that embraces the linux way of life. My result:
rm `find /path/to/backups/ -mtime +7 -name ‘*.bz2′`
The breakdown:
Slap that sucker into a cron job and you have yourself an automated way to maintain a certain number of files that do not exceed a certain time frame. find is enormously useful and has so many wonderful options to assist you in your file searching. So there you have it, a simple one-liner to remove files based on their timestamp.
Via BoingBoing, a video remix of a scene in Empire Strikes Back, making Lord Vader appear as a smart ass. Great stuff.