I have some directories that I have to go to a lot more often than others, like for music, work, programming, etc. So I want to have exclusive commands, say "gotomusic" or "gotodropbox" to go to these folders because otherwise I have to type something like cd /media/sda9/Work/Dropbox and so on.

Is it a good idea? Is there a better way of getting the same result?

I tried writing the following script "gotomusic"


cd /media/sda8/Music

But it does not work. What is wrong in doing so?



I think that you can find the right solution on stackoverflow:


| improve this answer | |

You may do this by using aliases, just add in your ~/.bashrc

alias gotomusic='cd /home/user/music'
alias gotopics='cd /home/user/pictures'


| improve this answer | |

The problem is, that you can't change the working directory of the parent process.

Related to your problem the procedure is as follows:

The current working directory of your interactive shell is $PWD. Then you start gotomusic and your interactive shell (i will call it parentbash) starts a new instance of bash (i call it childbash) as a new process. childbash inherits several attributes of parentbash. Among other things it inherits it's working directory from parentbash.

Since you instruct childbash to read the commands from your script it changes its own working directory to /media/sda8/Music and terminates.

At this point parentbash gets active again with the same state as before the execution of childbash.

In order that parentbash should invoke its cd builtin command you should source your script. This is easily done by

source gotomusic

But the question remains if this approach is well suited for a quick directory change.

There are several implementations of directory-bookmark systems bashmarks but i think the best solution would be that you can easily choose from a list of the most used directories. I don't know whether there exists something like this for bash but if you want to use zsh you can get it at [1].

| improve this answer | |
  • Wow that's interesting. I'd vote up your reply if I could :) – user1953384 Aug 2 '13 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.