Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Bash Startup Files

In bash, you can choose from one of 4 startup files to place configuration you want to run at user login: 1) .bash_profile 2) .profile 3) .bash_login 4) .bashrc

Which one should you use?

It’s recommended that you have a single .bashrc file with a symbolic link for .bash_profile pointing to the .bashrc file.

Login Shells

A login shell is typically what you get when you first login to a system. The same is true for when you ssh to a system. You can tell if you are using a login shell by typing in echo $0 at the shell. If you receive a - in the response, you are using a login shell. The basic idea is that the login shell is the initial shell. When bash runs as a login shell, it runs /etc/profile. This is a global profile file that applies to any user. It then looks for one of the four user-specific profile files mentioned above. It will run the first one that it sees.

Non-login shells

Graphical user environments such as GNOME start-up in non-login shells, unless you specifically ask for a login shell. Upon starting a non-login shell, bash runs /etc/bash.bashrc and then runs the users .bashrc