Reputation: 33
Assuming user is in dir1 and want to cd to dir2, how can he do it using cd by just telling that replace test with src in current working directory?
/home/user1/test/package/files/
/home/user1/src/package/files/
Upvotes: 0
Views: 134
Reputation: 263617
If you're using bash (the most common default shell), you could do this:
cd ${PWD/test/src}
If you're using zsh, it has a built-in feature for this:
cd test src
man zshbuiltins
and search for cd
.
(And both of these techniques can be used in scripts, so I'd argue that this is a valid programming question.)
On the other hand, depending on how often you do this and how many directories you're dealing with, it might make more sense to set some variables:
testfiles=/home/user1/test/package/files
srcfiles=/home/user1/src/package/files
cd $testfiles
cd $srcfiles
Upvotes: 1