Question

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

Was it helpful?

Solution

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

OTHER TIPS

What about setting up your CDPATH variable?

cd ^/a/^/another/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top