Thursday, January 19, 2012

bk - a useful alias to go back to the last directory in bash

i find myself going back to the previous directory i was just in all the time in a bash terminal, and instead of commands like:


cd /some/directory/
cd /another/directory/
cd /some/directory/


you can remember the command:


cd ~-


but it is more useful to have an alias defined in an aliases file (usually ~/.bash_aliases is easily sourced by your ~/.profile, or ~/.bashrc)

a few cd related aliases i tend to include:


alias ..='cd ../'
alias ...='cd ../../'
alias bd='cd ~-'


on a related note; there are other directory changing commands (other than cd) that are good to learn (and use for functions or aliases):  popd, pushd, and dirs.

--
hope u find this useful...

No comments:

Post a Comment