Technix
Technology Weblog

Cool trick to navigate directories using cd !


Everyone using Linux will like to use it to navigate easily between directories. Add the following code into .bashrc file. Now you can navigate foward and backward using cd ] and cd [ .

Cool !

    __COUNT=0 __BACK=0 cd () { if [ "${1}" = "[" ]; then if [ "${__BACK}" -lt "${__COUNT}" ]; then pushd +1 > /dev/null __BACK=$(($__BACK+1)) else echo "can't go back any more" fi elif [ "${1}" = "]" ]; then if [ "${__BACK}" != 0 ]; then pushd -0 > /dev/null __BACK=$(($__BACK-1)) else echo "can't go forward any more" fi elif [ "${1}" = "." ]; then builtin cd "${@}" else if [ "${1}" = "-" ]; then pushd "${OLDPWD}" > /dev/null elif [ "${#}" -eq 0 ]; then pushd "${HOME}" > /dev/null else pushd "${@}" > /dev/null fi while [ "${__BACK}" -gt 0 ]; do popd -0 > /dev/null __BACK=$(($__BACK-1)) done __COUNT=$(($__COUNT+1)) fi }

Add above code to .bashrc .

Advertisements

One Response to “Cool trick to navigate directories using cd !”

  1. Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: