I always loved use tmp directory to manage my “temporary files”. First of all, which files can be considered as “temporary”, and what does temporary exactly means? Well.. In my opinion, we can address as temporary all those files used only during a single Session. Such as:
- files downloaded from browser – typically “to take a look or a single read”, they will never be opened again.
- “text_files / notes / drafts / patches / etc..” – bound to be sent by email (and never used again).
- “apt-get source” – do you use it? 🙂
- many more … (pictures, samples, songs, backgrounds, code_branches, videos…)
If you use the standard $HOME/Downloads
(or the Desktop, or Home or whatever_you_use) directory to locate all those files, you already know which kind of mess will be there in few days, unless you do not spend part of your time to delete those files no longer used. Looking for a solution to this I figured out that set /tmp
directory (not really, but think about that) as my Download directory can be a good choice… It will be cleaned to each boot, so I can take no interest about files I download during a Session – and store only those I consider “important”, by moving to my “Downloads” (or “Documents”) directory. It can work, no? No. In fact that’s not all. I also love mount /tmp
in Ram in order to speed up a bit the system… And place my downloads in /tmp
can be dangerous for the system – sometimes downloaded files can be bigger than we expect (try to think to a 20MB pdf). So, one of the best way (in my opinion) to have a clean “downloads” directory is create a local ~/tmp
directory and use it as the default download directory for my Desktop and in the following lines I will show you how set it up.
Let’s start with mount /tmp in Ram, edit your /etc/fstab
appending the lines below:
# RAM Disks tmpfs /tmp tmpfs defaults 0 0
Next step, create a ~/tmp directory (or wherever you prefer) and set it as Downloads directory:
mkdir ~/tmp xdg-user-dirs-update --set DOWNLOAD ~/tmp
Now create a script able to clean the directory to each login. I choose a file named ~/.initrc (you can use it to launch other applications, like conky). Use your preferred editor and insert the following lines:
#!/bin/bash # Clean tmp dir: find $HOME/tmp -mindepth 1 -delete &
Save the file and link it into your “Startup Applications” (search it through Unity), I use the following:
That’s all. My simple way to have a clean Home directory.
I agree that ~/Downloads can get messy real quick.
But now, instead of a messy ~/Downloads directory with all the random stuff you’ve downloaded, you have a messy ~/tmp directory.
What’s the point?
The whole idea of ~/Downloads is that it will contain all that stuff we download and don’t care about, because if we did, we’d move it to ~/Documents, ~/Pictures, etc…
So why not just set your script to cleanup ~/Downloads and remove one level of indirection?
Because I also use ~/Downloads for other stuff, for instance to locate my torrents and podcast, files that I want to preserve 😉
You don’t?
No, when I want to preserve something it goes to a proper folder.
I use ~/Downloads exactly the way you use ~/tmp
You could also use something like /var/tmp/$USER-Downloads or similar and clean it up as you wish.
Right!.. But it’s not automatically cleaned (if I’m not wrong)… It’s just a manner of name…
Now everyone knows how to send your PC out-of-mem! 🙂
«Ehy, take this file .dsc»
… from now on, don’t trust me. LOL
Eh? 🙂
Why… As I said: I do not use /tmp (mounted in RAM) anymore to download my files… but ~/tmp instead 😛
uhm, ok, then I can’t catch the point. /tmp currently isn’t mounted as tmpfs.
Why you need to put it in ram?
If I understood correctly now, the only important bits of all your needs is the cleaning script. Or am I still wrong?
I’m with you Gaspa. The OP talks about setting up /tmp as tmpfs, but then he simply creates ~/tmp without any relation to /tmp…
You’re right… The point (maybe I miss there) is: I always used /tmp to download my files…
But, since one day I decided to it put in RAM, I have been forced to create a local tmp dir (~/tmp) and make a script able to delete the content during login (in the same way /tmp gets clean at boot).
Ah – The post is called ‘A smart way to use /tmp’ – that’s the relation you’re looking for. 🙂