Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
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
add comment

Your Answer

 
discard

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.