What is the difference between ~/.profile
and ~/.bash_profile
?
Bash – Difference Between ~/.profile and ~/.bash_profile
bashprofile
Related Solutions
The organization of configuration files is much less uniform than your questions seem to imply. There is no "class", there is no "hierarchy", and there is no global "configuration czar" nor committee that decrees a common syntax or other nice clean generalizations like the ones you are seeking. There is only a multitude of separate applications like R
, bash
, screen
and the GNOME desktop environment, all of whom have their own ways of doing things, so you should look at the documentation for each individual program to answer any specific questions about a particular file. If it seems ad-hoc, that's because it is: most of Unix / Linux software out there was developed for different purposes by different people who all went about configuration slightly differently.
To answer your other questions pointwise:
*rc
and*profile
do not mean very much, so this question can't really be answered. "rc" is merely a commonly used abbreviation or suffix for configuration files. Its etymology goes back to ancient times (in computer years), and probably means run commands (from runcom). Just because applications use the same word does not mean they agree on conventions. "profile" is a much less common suffix.Define "scope". Most applications do not share configuration files with other non-related applications. The one possible exception is
/etc/profile
and.profile
, which may be used by multiple different shells (including at leastsh
andbash
). There is something called an environment associated with every running process which can contain variables that may affect the behavior of said process. Generally, environment variables are set by the appropriate shell configuration files, or perhaps the configuration files of whatever graphical desktop environment you are using. There are also configuration files for "libraries", like.inputrc
for readline and.gtkrc*
for GTK, which will affect every application that uses the library.No, there is no global hierarchy for configuration files. Again, refer to the documentation for the specific program in question, for example, the
bash
manual forbash
. A general convention you can usually rely on is that user settings in$HOME
override system-wide configuration in/etc
. This is typically accomplished by reading the user file after the system one, so that later settings overwrite earlier ones. However, this is not a guarantee, and for definitive answers you should refer to the documentation for the specific program you are using.There is no "class", at least none general enough to encompass all the files you've listed in your question, so the question of a reference for such a "class" is moot. Again, refer to the documentation of the specific program you are using.
The .profile
dates back to the original Bourne shell known as sh
. Since the GNU shell bash
is (depending on its options) a superset of the Bourne shell, both shells can use the same startup file. That is, provided that only sh
commands are put in .profile
For example, alias
is a valid built-in command of bash
but unknown to sh
. Therefore, if you had only a .profile
in your home directory and put an alias
statement in it, sh
would complain. So there is a bash specific file that has shell initialization commands which bash will read if and only if there isn't a .profile
file present.
Actually that's a bit of an oversimplification in some installations, and I'm not familiar with Fedora. Under bash, /etc/profile
is read by the shell before any files in your home directory. If there is a system wide initialization script it often says something like
if there is a $HOME/.profile:
source it
elseif bash is my shell and there is a $HOME/.bash_profile:
source that
Why is that way? An attempt at compatibility across decades of shell dialects. Why is the tutorial written that way? The Bourne shell is not often used much any more and some people don't even know that there is any other Bourne-like shell than bash. Even when the (limited) Bourne syntax is used for greater cross-platform compatibility it is often being run by dash
or bash in POSIX compatibility mode. Indeed, the actual Bourne shell source is probably a copyright component of Unix System V which appears to be the property of Novell now but I have no idea what, if anything, they are doing with it.
For the beginning user, use either $HOME/.profile
or $HOME/.bash_profile
but not both and you'll be fine. Since you already have a .bash_profile
work with that because it may have system specific stuff in it that your installation needs.
Best Answer
The
.profile
was the original profile configuration for the Bourne shell (a.k.a.,sh
).bash
, being a Bourne compatible shell will read and use it. The.bash_profile
on the other hand is only read bybash
. It is intended for commands that are incompatible with the standard Bourne shell.