Is there an easy way to force the Terminal to run a command every time it is launched on macOS?

I did some searching on here and most of the time this question is asked on here with regards to Ubuntu but I can't find a Mac solution. For Ubuntu, everyone says to use bashrc but that file isn't in my home directory.

Many thanks.

2 Answers 2


The most common way is to add the command to .bash_profile file in your home directory.

Quoting man bash which lists other options as well:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

  • Thank you, your answer worked. However, I found it strange that I didn't have a .bash_profile in my home directory. I created it, added the command on there and restarted Terminal and voila! Dec 16, 2016 at 15:07

If you want to run a command when Terminal.app opens a shell, not just for any interactive shell:

  1. Open TerminalPreferencesProfiles.
  2. Select the profile you use, then switch to the Shell tab.
  3. Under Startup, enter the command you wish to run as the Run command.

You must log in to answer this question.

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