tags:

views:

173

answers:

3

I know a few advanced ways, to change directories. pushd and popd (directory stack) or cd - (change to last directory).

But I am looking for quick way to achieve the following:

Say, I am in a rather deep dir:

/this/is/a/very/deep/directory/structure/with\ lot\ of\ nasty/names

and I want to switch to

/this/is/another/very/deep/directory/structure/with\ lot\ of\ nasty/names

Is there a cool/quick/geeky way to do it (without the mouse)?

+9  A: 

Do you mean that the path names are the same, and only one directory name changes ("a" becomes "another")? In that case:

cd ${PWD/a/another}

will switch to the other directory. $PWD holds your current directory, and ${var/foo/bar} gives you $var with the string 'foo' replaced by 'bar'.

dF
Perfect - exactly, what I was looking for. Thank you!
Mo
+2  A: 

What about setting up your CDPATH variable?

Rob Wells
+1  A: 
cd ^/a/^/another/
slipset