Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using with and so I have say two different directories say:


So to set up my enviroment I normally go to ~/Development/site1 then run source bin/activate. Is it possible to have that command run automatically when I cd into one of these directories?

share|improve this question
See this recent U&L question:… – enzotib Sep 25 '11 at 16:08
up vote 3 down vote accepted

You could put this in your .bashrc to redefine the "cd" command:

    [ -z "$*" ] && builtin cd $HOME
    [ -n "$*" ] && builtin cd "$*"
    [ -f "./bin/activate" && source ./bin/activate
share|improve this answer

Would a bash alias suffice? or does it have to be linked to entering the specific directory?

My solution to bash alias.

In ~/.bashrc check that .bash_aliases is ran.

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases

In ~/.bash_aliases

alias siteone='cd ~/Development/site1 && source bin/activate'
alias sitetwo='cd ~/Development/site2 && source bin/activate'
share|improve this answer
I'll end up doing this instead I think, thanks. I accepted @user25618 answers because it's more correct for the question. – Kit Sunde Oct 7 '11 at 17:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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