Introduction
The start-up Bash commands, variables, aliases and cutomizations are put in ~/.bashrc
, ~/.bash_profile
, ~/.profile
files. So whenever you open a new terminal, one of these files is called first, but which one?
Prerequistis
It’s good to know about Shell terminal and its commands.
.bashrc vs .bash_profile vs .profile
The difference between them is that:
.bashrc
is run by non-login shells. In other words, if you start a terminal without any authentication, the.bashrc
is run. One example is, when you are already logged in your Ubuntu Desktop and you open a new terminal. Another example is, with VS code, you are connected to a remote server, any terminal you open there runs.bashrc
first..bash_profile
is called when we enter a login shell (Bash). For example, SSH to a remote server with username and password..profile
, this is the originalsh
profile file. If.bash_profile
not found,.profile
will be loaded.
So my advice is for a local Linux, add commands to ~/.bashrc
, for remote servers do the same, but also add the below line to ~/.bash_profile
:
source ~/.bashrc
This guide was for Bash terminals, but for other Shell terminals you probably need to set slightly different files, for example, zsh
uses .zprofile
and .zshrc
.
Latest Posts
- A C++ MPI code for 2D unstructured halo exchange
- Essential bash customizations: prompt, ls, aliases, and history date
- Script to copy a directory path in memory in Bash terminal
- What is the difference between .bashrc, .bash_profile, and .profile?
- A C++ MPI code for 2D arbitrary-thickness halo exchange with sparse blocks