LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Can I make 'cd' behave this way? (https://www.linuxquestions.org/questions/linux-software-2/can-i-make-cd-behave-this-way-87012/)

exitsfunnel 08-29-2003 12:22 PM

Can I make 'cd' behave this way?
 
Hello,

I'm a pretty new convert from Windows to Linux. In general, I quite like working (I'm a software developer) on Linux but there are a few wrinkles I'm still trying to iron out. One such issue involves navigating directories with 'cd' I often need to move back and forth between several directories each of which is quite deeply nested in separate hierarchies. I'd like to be able to provide the shell (I use bash) with a set of directories such that when I type 'cd foo' if it can't resolve 'foo' to the current directory it will search the list and execute the appropriate command if there is foo relative to one of the entires. Is there already some means to accomplish this? I'm considering writing a shell script but I'd rather not spend the time if the functionality already exists in some form. Thanks in advance for any replies.

-exits

david_ross 08-29-2003 12:52 PM

You could create simple alisases eg:
alias cdsrc='cd /usr/local/src'

Then to get to the src dir:
cdsrc

lyle_s 08-29-2003 06:38 PM

You're describing the CDPATH environment variable.

Have a look at man bash for more detail.

Lyle

exitsfunnel 08-30-2003 05:38 PM

Thanks Lyle!
 
Thanks Lyle, that was exactly what I was looking for. I figured there had to be a way to do it.

-exits

devoyage 08-30-2003 05:57 PM

try cd'ing around and then type:

dirs -v

if you want to go to one of the directories, use:

pushd +n (where n is the the stack number of the dir)

These can be placed in some functions/aliases to make them a little less cumbersome to use.

enjoy


All times are GMT -5. The time now is 11:36 PM.