Home » Linux Basics » 04 - Environment, Configuration, and Programming
4

Configuration Files

Setting environmental variables and aliases permanently

Configuration Files

You may wonder how, when, and where environmental variables and aliases are set 'permanently'. Certain files are executed each time a user logs in. The filenames of these files begin with a dot (.). Due to this, such files are also referred to as dotfiles. Dotfiles are executed when the user logs in or starts a program; the content of these files is used to set important configuration parameters such as basic environmental variables that correspond to the path, prompt and so on. Most utilities and programs automatically reference corresponding dotfiles. Most of the variables displayed in response to the 'set' command come from dotfiles that were executed upon user sign-in.

The bash shell uses the following files to customize the user's environment upon login. These files are usually found in the home directory; issuing the 'ls .*' command in the home directory will show all the files. If the files are not found in the user's home directory, the shell uses the versions in /etc/profile

  1. .bash_profile/.bash_login/.profile : Executed by the shell each time the user logs in. The bash shell only executes one of the three files: If .bash_profile cannot be found, .bash_login is used . If both cannot be found, .profile is used.
  2. .bashrc : Executed by shell when a new shell or subshell is opened.
  3. .bash_logout : Executed by shell when user exits.

Common Dotfiles

name Description
.emacs Used by the emacs editor
.exrc Used by the vi editor
.newsrc For newsreaders - contains bulletin board lists
.xinitrc Used by x-windows; executed when X-Windows is fired up

The source command may be used to make any changes to dotfiles immediately effective (rather than upon the next login). If the user changes the PS1 variable definition within the .bash_profile file and he wants to see the new prompt right away, he may use the source command. Note that the prompt changes to reflect the user's new definition right after the source command:

    [ LinuxUser ] /usr/bin$ source .bash_profile
[LinuxUser Sat Nov 25] /usr/bin$