What are the functional differences between the .profile
, .bash_profile
and .bashrc
files?
Linux – What are the functional differences between .profile .bash_profile and .bashrc
bashlinuxprofileUbuntu
Related Topic
- Linux – the purpose of each of the different UNIX/Linux shell startup files
- Bash – the difference between double and single square brackets in bash
- Ssh – .bashrc or .bash_profile for ssh-agent
- Linux – What are the major practical differences between OpenSolaris and Linux
- Bash – Both bashrc and bash_profile won’t seemingly source? VirtualMin Clean install
- Linux – the difference between “sudo -i” and “sudo bash -l”
- Ubuntu – .bashrc not loaded, .bash_profile exists
Best Answer
.bash_profile
and.bashrc
are specific tobash
, whereas.profile
is read by many shells in the absence of their own shell-specific config files. (.profile
was used by the original Bourne shell.).bash_profile
or.profile
is read by login shells, along with.bashrc
; subshells read only.bashrc
. (Between job control and modern windowing systems,.bashrc
by itself doesn't get used much. If you usescreen
ortmux
, screens/windows usually run subshells instead of login shells.)The idea behind this was that one-time setup was done by
.profile
(or shell-specific version thereof), and per-shell stuff by.bashrc
. For example, you generally only want to load environment variables once per session instead of getting them whacked any time you launch a subshell within a session, whereas you always want your aliases (which aren't propagated automatically like environment variables are).Other notable shell config files:
/etc/bash_profile
(fallback/etc/profile
) is read before the user's.profile
for system-wide configuration, and likewise/etc/bashrc
in subshells (no fallback for this one). Many systems including Ubuntu also use an/etc/profile.d
directory containing shell scriptlets, which are.
(source
)-ed from/etc/profile
; the fragments here are per-shell, with*.sh
applying to all Bourne/POSIX compatible shells and other extensions applying to that particular shell.