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(){                                                                                                                   
    local td=$TD                                                                                                        
    if [ ! -z "$1" ]; then                                                                                              
        td="$HOME/temp/`date -d "$1 days" +'%Y-%m-%d'`";                                                                
    else                                                                                                                
        ln -s -f -T $td "$HOME/temp/00-today"                                                                           
    fi                                                                                                                  
    mkdir -p $td;                                                                                                       
    cd $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: