.bashrc is a shell script that Bash runs whenever it is started interactively. You can put any command in that file that you could type at the command prompt.
You put commands here to set up the shell for use in your particular environment, or to customize things to your preferences. A common thing to put in
.bashrc are aliases that you want to always be available.
.bashrc runs on every interactive shell launch. If you say:
$ bash ; bash ; bash
and then hit Ctrl-D three times,
.bashrc will run three times. But if you say this instead:
$ bash -c exit ; bash -c exit ; bash -c exit
.bashrc won’t run at all, since
-c makes the Bash call non-interactive. The same is true when you run a shell script from a file.
.profile which are only run at the start of a new login shell. (
bash -l) You choose whether a command goes in
.bash_profile depending on on whether you want it to run once or for every interactive shell start.
As a counterexample to aliases, which I prefer to put in
.bashrc, you want to do
PATH adjustments in
.bash_profile instead, since these changes are typically not idempotent:
If you put that in
.bashrc instead, every time you launched an interactive sub-shell,
:/some/addition would get tacked on to the end of the
PATH again, creating extra work for the shell when you mistype a command.
You get a new interactive Bash shell whenever you shell out of
:sh, for example.
You may view and edit file using the command below.
sudo gedit ~/.bashrc