Mo.
Mo.

Reputation: 15353

Advanced directory switching in bash

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

Upvotes: 9

Views: 499

Answers (3)

Rob Wells
Rob Wells

Reputation: 37159

What about setting up your CDPATH variable?

Upvotes: 3

slipset
slipset

Reputation: 3078

cd ^/a/^/another/

Upvotes: 1

dF.
dF.

Reputation: 75845

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

Upvotes: 10

Related Questions