A user-specific (not systemwide) configuration script executed when starting login shells.
.profile
is a file in each user's home directory (for example /home/octavia/.profile
) that is run for login shells only. This means it will definitely be read by bash when the user logs in on a TTY (virtual terminal), but will not usually be read by bash when opening a terminal emulator inside a graphical shell. However, since the file is usually read by the graphical shell when the user logs in, variables set there may be inherited by other shells. It is therefore one place that may be used to set or modify some user-specific environment variables.
The file .profile
is normally read in Ubuntu because we do not typically have a file ~/.bash_login
, which would be read in preference to ~/.profile
if it existed, or a file ~/.bash_profile
which would be read in preference to either of those files.
Here is an example of a .profile
in Ubuntu
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
As shown, ~/.profile
can be used to set a umask for the user, overriding the one set systemwide by /etc/profile
.
The code then checks to see whether the shell being run is a bash shell, and if it is, reads the user's ~/.bashrc
. This means that any customisations (such as PS1 definition, aliases and functions) made in ~/.bashrc
will be available in shells that read ~/.profile
but not ~/.bashrc
directly, unless they are overidden by commands later in the file.
Finally, the code checks to see whether the user has a directory ~/bin
and if it does exist, it is added to their PATH variable. This means that users can place applications in this directory, and call them without the full path.
Additional customisations can be added to the end of the file.
Some popular questions: