Garbage Collected Directories
“I wish all these temporary directories wouldn’t clutter my home directory.”
We are all familiar with directories cleverly named “tmp”, “test”, “whatever”, or “DELETE-ME”. These directories are usually created for short-lived experiments or to contain a “mess”.
For example: you download a package, untar/gunzip it,
./configure; make; make
install. You start to play with what you installed and forget about the
directory you’re leaving behind. That clutter will haunt you later.
I created a simple script to clean up after myself, I call it
__d__irectory). The code is on Github, but
here’s a snapshot:
This creates a directory under
$HOME/.throw-away, changes (cd) into it and
launches a shell there. When the shell exits, the directory is deleted with all
In practice, it means that I type
tad and I’m in a sandbox. And when I exit
the shell, the sandbox is gone and I’m back in the original directory from
which I issued the command. This script is the formalization of something I
used to do manually.
What does it mean to have garbage collection for directories?
It changes the way you work. I have had this script for quite some time: I use it all the time and keep finding new ways to use it. Not having to name the directory and not having to clean up frees me – those things are accidental complexity.