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!

1 Comment

  1. Evan 'JabberWokky' Edwards Said,

    May 31, 2009 @ 7:35 am

    I have the same thing in terms of keeping my $HOME swept clean of files, only I like to be able to reach back and grab things from awhile ago. Plus, disk space is cheap. So I have (in my $HOME):


    And a command “sweep”, which tucks everything that is not supposed to be in my $HOME into I have burn, doc, host.frank(1), inbox.*, usr, wiki and www. Everything except host.frank and burn and pub(2) are a link into usr, and that’s backed up across the network. All the above day directories are links into host.frank/ATTIC/%Y/%Y.m/%Y.m.d/.

    I also have a gtdlink app that runs at 4am and relinks the, etc directories into the host.$HOSTNAME/ATTIC hierarchy, thus pushing back today to yesterday. Any files in (which used to be tomorrow) are then moved to $HOME and images and desktop files (reminder web links, mostly) launched. Thus I can drag in reminders to any date in the future and they appear in my $HOME on that day, and are launched, sitting and ready for me on my desktop when I sit down.

    Oh, I also “collapse” inbox.* projects when they are done. So I might have a inbox.virginvoices.rewrite. When I’m done, I rename it simply virginvoices.rewrite, and it hits the temporal stream and is swept up.

    There are a handful of other refinements (I mark the directories yellow, or if the day of the week is Saturday or Sunday, red), but that’s the basic idea. Every so often I whack at host.$HOSTNAME/ATTIC to keep the size down, but it’s basically a trailing (and leading) queue I pass through in realtime, sweeping up downloads and temporary files in case I want to locate (often literally locate, a la updatedb) them.

    1 – Each computer on my network has a $HOME/host.$HOSTNAME for all users, frank just happens to be my current primary desktop. It’s the local file section, but the name is also handy to know where you are.

    2 – burn and pub are basically links to my home file server, and are inbound and filed media, respectively.