//View Tip #310
Similar Tips
» Deleting whole words on a bash command line
» Store a directory name to come back to
» Permanent bash history
» Check low space
» Find files greater than a certain size

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Seen on http://www.splitbrain.org/blog/2008-02/27-keeping_your_home_directory_organized

Having one temporary directory for downloads etc can quickly become a mess, so try this tip to organise by date. Put this into your .bashrc


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
}


You'll receive a new function 'td' for making temp-dirs under $HOME/temp/ named by date. It is also possible to switch days back with 'td -[n]', i. e. 'td -3' which means '3 days back from now'.


View Comments »




Comments 

Add your comment

Comments are currently disabled
Jim
The only problem I see with this little tidbit is that if you are working around midnight.  If you use td before midnight, and are still logged in after midnight, then $TD is still set to yesterday.

Move the TD=.... to inside the function to fix that.
Posted 2009-04-15 12:28:17

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit