When you say "get cleaned up automatically when I lose interest in them", it is pretty subjective and can vary from person to person. That said, the word "automatically" immediately brings the cron utility into mind. Here is a simple one-time setup that should address your requirements (or at least part of it). Please note that I am not claiming to cover all possible scenarios and advanced usage, just trying to help the OP.
Overview:
- Define an alias to create directory with a random name, but with a pre-assigned suffix.
- Use this alias instead of mktemp whenever you want to create a tempdir. It will spit out the name of the tempdir when you run it and it will always create the dir in /tmp.
- Run a cron job to find and remove these temp directories, but matched with certain criteria (e.g. older than 30 days).
Detailed steps:
Define the alias called mktmpdir (you can put this in your ~/bash_aliases or ~/.bashrc):
alias mktmpdir='mktemp -d --suffix=.delme'
-d (create a directory, not a file)
--suffix=.delme (always add a suffix called .delme to dirs. Note the period)
Run crontab -e to add the cron job which will clean out directories with modification time older than 30 days (there are many options to the find command, just read the man page):
0 5 * * 0 find /tmp -type d -ctime +30 -name *.delme -user YourUserName -exec rm -rf {} +
Explanation of options:
- 0 5 * * 0 (run this job at 5 AM on Sundays)
- -type d (only directories)
- -ctime +30 (older than 30 days)