Bash startup files


From the bash man page:

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. The --noprofile option can be used when the shell is started to inhibit this behavior.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This can be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc

Every new terminal window/tab that you open will load .bashrc

On a brand new user account, none of these files will exist, they can be created with any suitable text editor that is capable of creating plain text files with unix style (LF) line endings. Save them into your home folder (~/)

Commands you will typically want to include in .bashrc include: history variables to increase the history available and bind keymappings.

Other startup files


Adding aliases to a separate file called .bash_aliases has the same affect as putting the aliases in .bashrc the advantage of .bash_aliases is that having all your aliases in one file makes it easier to re-load them when you make changes.
This file is not automatically loaded, so add the following to .bashrc to load it at login:

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

The command . ~/.bash_aliases will source (load) ~/.bash_aliases in the context of the currently running shell.


bash prompt - PS1
bashrc_dispatch - use symlinks to reorganise .bashrc, .bash_profile and .profile
.inputrc - Startup files (Set Key bindings and Tab completion)
bashrc example - Tom Ryder
alias - Create an alias

© Copyright 1999-2016
Some rights reserved