Bash – Any cd shortcut to switch an intermediate directory in current path

bashcd-command

if I have current path as a long one..and I want to switch to a directory with just one word from path replaced by something else..like say when using maven , I want to switch from main path to test path, how do I do it?

Some time back, I was able to do it by

$ cd main test

to replace main by test in the path, but not any more..

Any pointers…?

Best Answer

You could use a simple function for that (put it in your .bashrc or something like that):

function bcd {
    cd ${PWD/$1/$2}
}

Then you call it like this:

~/tmp $ bcd tmp src
~/src $