Subscribe to RSS feed

splitbrain.org - electronic brain surgery since 2001

Keeping your Home Directory Organized

I'm an avid Linux user. What to most Windows users is their Desktop, is my home directory to me. When ever there is a download to save, a file to create or an archive to unpack – it will be done in my home directory.

This quickly turned into a mess in the past. My first attempt to solve the problem was to use a subdirectory called temp. Of course this didn't solve anything, it just moved the problem to a different directory.

The system that finally worked for me is using daily temp directories. To make this easy to manage I use a simple command defined in my ~/.bashrc. Let's have a look at the code first:

export TD="$HOME/temp/`date +'%Y-%m-%d'`"
td(){
    td=$TD
    if [ ! -z "$1" ]; then
        td="$HOME/temp/`date -d "$1 days" +'%Y-%m-%d'`";
    fi
    mkdir -p $td; cd $td
    unset td
}

The command is called td. When called it checks if today's temp dir already exists or creates it if necessary. It then changes into the directory.

The command also accepts an argument to access previous temp directories. Just add a minus and the number of days you want to go back.

Quick example? It works like this:

~$ date
Wed Feb 27 20:24:37 CET 2008
~$ td
~/temp/2008-02-27$ td -2
~/temp/2008-02-25$

Additionally to the td command a variable called $TD is defined. It just points to today's directory. This is quite handy if you need to copy something from or to your temp directory.

My new system helps me to have a clean workspace for trying stuff everyday. All I have to do is to delete old temp dirs from time to time when disk space becomes scarce.

What's your way to keep your $HOME clean and your mind sane?

Tags:
linux,
bash,
temp
Similar posts:
Posted on Wednesday, February the 27th 2008 (24 months ago).

Comments?

1
Neat trick!

I do something very similar!  I have my entire home directory in mercurial version control, and if I don't run hg add on something, then it's clearly not important enough to save or a program generated it for me.  

So I run a script that takes all files that haven't been added, and moves them to ~/zip (don't ask why it's named zip, I don't know either).  The neat part is it also keeps the directory hierarchy.  So if I put a file in ~/doc/resume/beta.tex but forget to hg add it, it gets moved to ~/zip/doc/resume/beta.tex.

Now I forget to clean out ~/zip a lot... but if I don't LOOK at ~/zip for months at a time, clearly the data is not important, and I just run rm -rf ~/zip.

It's neat we both took the same versioned approach to our files, in very different fashions ;)
2008-02-27 21:24:10
2
I lost it in a reformat, but I had a system that involved a "downloads" folder on my desktop (yup, windows user), and a firefox plugin which would auto-choose a subdir in "downloads" based on file type.  All my installers went in one folder, media (pictures, movies, music) went in another, etc, etc.  I also had these folders sort by last date accessed, so that stuff I hadn't looked at in a while floated to the top.  Every once in a while I'd just skim off the top in each subdir.

My system before that was a "temp" folder which overflowed with stuff I wanted to keep but was too lazy to organize-  So I made a "temp2" folder, thinking, "okay- this one I'll keep clean."  And renamed the "temp" folder to "downloads".  3 or 4 temp folders later, I realized this was a horrible idea, so I moved to the system mentioned above.

I really dig your system too, though.  My only problem with it is that, now that I'm a web developer for a living, "TD" has what you might call a "mental namespace collision".  Of course, that's entirely subjective, I'd just probably change the title if I built a linux box and decided to use that snippet:P
2008-02-27 22:34:34
3
I like that, and I think I'll make it a constant part of my .zshrc. Thanks for sharing :)
2008-02-27 22:59:37
4
Thank you for this one, I also added it to my ZSH configuration. And pushed it directly into my GIT repository: http://goatpron.de/cgi-bin/git … ;a=summary
2008-02-28 00:00:23
5
Nice trick indeed!

I've checked my ~ into a git repository lately. But only for my configuration files for now. I manage a quite strict directory structure, for downloads I have a dedicated "downloads" directory for example. And whenever I come across something that I know I don't need anymore, I delete it instantly. However, I really like your approach, I'll give it a try and see if it fits my needs as well :).
2008-02-28 00:01:05
6
Really cool, i'll give it a try too!
Thanks! :)
2008-02-28 11:39:33
kevin
7
Interesting idea, you could push it a little further and automatically store all daily temp folders of a given month together in the same folder. Also, I wonder if there is an option in Firefox configuration files that one can change at boot time so that downloads go to the temp folder of the day instead of ~.
2008-02-28 15:56:46
8
I'm sorry but this time I don't agree with you. :)
What I do? I simply use ~/Desktop :) and my rule is "don't let it increase to more than two columns of icons". That's it!
2008-02-28 21:24:21
9
I have at least 4gb of assorted software I've downloaded and long-ago bit the bullet to organise these by category. Yep, it's painful even thinking of the categories but once done can save a heck of a lot of pain finding things. I write the folder out to a DVD periodically.
e.g.
Desktop Software
Multimedia and Music
Security/Encryption
Security/AV
etc.
For backups on the webserver and daily tidying or code backup I wrote a small util for Windows called mkdate - initially in VB but later in C which lets you create temp folders by date then spawn off another app such as a batch script to run say 7-zip and backup everything into that folder. Win32 is a pain as it doesn't let you directly change the master ENV copy though. At least I don't have the code to do what I could do in DOS using Win32!! LOL
It's a bit quirky but does the job for me:
http://mkdate.amadis.sytes.net/
2008-03-04 15:49:51
10
What's wrong with ~/Desktop? And just deleting stuff right after you don't need it anymore? :-/
2008-12-25 04:28:32
Dan
11
Interesting.  Ideally, we should go through our stuff each day and keep it organized, but that obviously doesn't happen (just like with me.)  I think the daily temp directory is really interesting, because if I forget to go through and organize the files I've gone through on one day, I don't have to sift through a really large temp directory; I often remember approximately when I accessed and saved certain files, so even if I don't necessarily know the filename of what I'm looking for (I'm sure that happens to you all the time too), I'll know where to look for it, and it won't be in a directory that has hundreds of other files.

Thanks for the tip!
2009-01-04 10:41:01
James
12
Its very simple, just use DownThemAll download manager and organize the download folder by types of files or select the appropriate folder for destination.

~/Documents
~/Music
~/Pictures
~/Archive
~/Workspace
~/Projects
~/ISO
~/Downloads

just do the job
2009-01-15 16:43:42
blink4blog
13
I bet nobody has a more messy home directory than mine, when I want to note something, I don´t use 2do files neither sofware like tomboy, I just create a new file in ~/ like `touch read-krishnamurty` or `touch girl-phone-555xxx` and I find my stuff very quickly with a filtered ls. I also has a tmp dir on my home, I will try this script to see if works for me.
2009-02-01 20:09:21
14
I always do my downloads and work on temp stuff in /tmp.  I install tmpreaper (tmpwatch on RH) and set my TMPTIME between 7 and 21 days.  That way, all the files that I haven't used for $TMPTIME days are deleted once a day.
2009-02-07 22:24:21
15
I hope that nepomuk will solve this problem...
by the way... nice post... it gives me ideas
2009-02-19 14:23:02
CAPTCHA

No HTML allowed. URLs will be linked with nofollow attribute. Whitespace is preserved.