//View Tip #201
Similar Tips
» User input timeout
» List non-system users
» Keeping your Home Directory Organized
» Counts files in the current directory and subdirectory
» swap files


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
Put the following alias in your profile to store a directory name to use later on:
alias sd='set \!:1=$cwd'

Example usage:
$ sd mydir
$ cd mydir

This method works for csh but not bash. For bash try the following function in your profile:
sd(){ export $1=$PWD; }

$ sd abc
$ cd $abc

View Comments »


Add your comment

Comments are currently disabled
How about pushd and popd? Those who don't know UNIX commands are condemned to re-invent them.
Posted 2008-12-28 03:26:28
A nice compliment to this is

set | grep '^[a-z]'

Since bash variables and the body of all shell functions do not start with lower-case letters, this leaves a manageable list to look through, to remember which variables you set. If you start them all with 'a', they'll sort to the top.

AdrianTM: yes, pushd and popd have their place, as does 'cd -'. I find pushd and popd rather cumbersome, perhaps that's just because I don't know them very well. This tip is very light weight; I will definitely be adding it to my .profile.
Posted 2009-08-14 23:24:33

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit