19

I've tried putting

cd /Users/my_name/my_directory/structure

in both .bashrc and .bash_login but neither works, i.e. when I open a new terminal window I am in my home (/Users/my_name/) directory.

No error messages, just not cd'd into the directory as hoped when starting a new terminal window.

5

As Gerry mentioned, .bashrc is not read by login shells. New tabs are login shells by default in Terminal and iTerm 2. .bash_login is only read if there's no .bash_profile.

You could also add a cd command to .bash_profile.

33

First of all, if you are not using iTerm2 already, I suggest you download this free software as a replacement for Terminal.app.

Among many other extra features, in iTerm Preferences, you can configure the default working directory for new shells. You'll find these settings in Profiles - General.

iTerm Default Working Directory

The advantage here is that you can set different behaviors for opening a new window vs opening a new tab or even creating a new split pane. I personally like staying in the current working directory when adding a split pane, for example.

You could do it in your startup script as well (though I find the iTerm solution cleaner, or at least more flexible), but then I advise you to use ~/.bash_profile instead.

~/.bashrc is not automatically sourced when opening a new shell window, and ~/.bash_login is only sourced if no ~/.bash_profile is present.

  • 1
    I always source my .bashrc from my .bash_profile so I don't have to remember which is called from where. – CajunLuke Aug 30 '12 at 22:52
  • @CajunLuke I do something quite similar: github.com/gerryvdm/dotfiles – Gerry Aug 30 '12 at 22:55
  • If modifying Working Directory’s “Directory” field has no effect, you probably need to switch Command from “Command” to “Login shell” (source). – duozmo Feb 10 '16 at 17:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .