My Auto-Delete System

This is by far one of my best computer-based inventions, and yet is the most simple think I’ve ever come up with and installed. The origin is simple: I hate cleaning up old files on my system. When I started thinking about it, most of my files were things that I really only expected to have a short life-expectancy. You know, like those silly pictures people send you. Or Word documents you need to open and read once. Or … you get the point. I decided that most of these fell into four basic timing categories:

  1. Files that were truly intended to be short-lived.  On the order of hours.
  2. Files that I needed only for today.
  3. Files that I needed for a bit longer, but not a really long time.  Like a week.
  4. Files that I needed for something on the order of a month.

So I created 4 directories (folders to some of you) and made them be auto-cleaned on a regular basis.  The cleaner would remove things that hadn’t been looked at within the time period I selected for the folder.  It’s as simple as that.  The 4 directories I created were called h, d, w and m.  You can probably guess what each one means.  I put them as subdirectiories of ~/tmp but you could put them anywhere.

This example implementation assumes unix-like OS which is pretty much everything but windows. But I know there are cron systems out there for windows too. The important aspect of cron is that it lets you run commands on a regular and scheduled basis.

Here’s the crontab entries for my auto-cleaning system.  I used tmpwatch on my system but you just as easily use the find utility as well.

11 2,7,11,15,19 * * * /usr/sbin/tmpwatch 1 /users/hardaker/tmp/h
21 2,7,11,15,19 * * * /usr/sbin/tmpwatch 24 /users/hardaker/tmp/d
31 2,7,11,15,19 * * * /usr/sbin/tmpwatch 168 /users/hardaker/tmp/w
41 2,7,11,15,19 * * * /usr/sbin/tmpwatch 744 /users/hardaker/tmp/m

That’s it!  Drop things in the various folders based on how fast you want them auto-removed and you’re done.

The month based folder is the most interesting.  Basically stuff I put there is stuff that I expected to look at but if I forget to ever look at it within a month, it’s likely I never will.

For those needing first help with cron, run crontab -e and cut and past that into your editor when it pops up. Done!

Comments (1)