Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...?

share|improve this question
up vote 6 down vote accepted

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 $ 
share|improve this answer
Also, cd - can be very useful in the described situation (to quickly change back and forth between the paths). – rozcietrzewiacz Oct 30 '11 at 21:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.