Linux .bash_profile File

The bash shell provides a lot of features that can be configured by using bash configuration files like /etc/profile , ~/.bash_profile , ~/.bash_login etc. The .bash_profile file is located in the current user home directory as a hidden file. In some distributions may use the ~/.bashrc according to the .bash_profile file. In this tutorial, we examine how to find the bash profile file and create it if it doesn’t exist.

Bash Configuration Files

Bash provides different configuration files. The /etc/profile file is used by all users in a Linux system and first, these configurations are applied to the bash shell. And the .bash_profile is located under every user home directory where every user may have different bash configurations. This configuration file overwrites over /etc/profile configuration.

Create .bash_profile File

By default, the .bash_profile is not created by most of the Linux distributions. Actually, the .bash_profile is a normal text file that contains bash configuration like regular bash commands. We can create .bash_profile file like below.

$ touch ~/.bash_profile

The previous command only creates the .bash_profile file but does not open it to make some changes and configurations. Alternatively following command can be used to create if not exist and edit the .bash_profile file.

$ nano ~/.bash_profile

Configure .bash_profile File

Bash provides a lot of features even a programming language. All of them can be configured via a bash shell. Also, the .bash_profile file is used to configured newly opened bash shells or terminals. For example, the command prompt is set with the PS1 environment variable and the bash shell command prompt can be changed by setting a new value for the PS1 environment variable in the .bash_profile file.

export PS1 = "$ "

Open Another User Bash Profile File

The tilda ~ is used to locate the current user home directory but what if we need to open another user bash profile file. We can use the absolute path of the .bash_profile file. In the following example, we open the user ismail bash profile file.

$ vim /home/ismail/.bash_profile

Backup Bash Profile File

Bash profile file changes over time and if there is a big change this may break the profile file. Taking backup of the bash profile file regularly is a good habit. It is very easy to take a backup of the bash profile file. Generally the name .bash_profile.bak is used as the backup file name for bash profile.

$ cp ~/.bash_profile ~/.bash_profile.bak

Systemwide Profile File “/etc/profile”

The /etc/profile file is used as a system-wide profile file where before loading a user-specific profile file this profile file is executed and applied. This system-wide profile file contains checks about shell type, user ID, and loading multiple profile files via /etc/profile.d directory.

Systemwide Profile File “/etc/profile”

Leave a Comment