Create the .bash_profile file
Open the command with a shortcut key Ctrl + Alt + T or from the side icon of the terminal. The command is open. First of all
, you need to create a .bash_profile file using a touch command in the terminal shown below: This is the easiest way to create a file in a terminal,
and it will not display any message that a file has been created.
List the file
When you search for the .bash_profile by checking it in File Explorer, You cannot find the file because it is hidden. On the other hand, you can search for
the newly created .bash_profile file using the list command as:
Open the .bash_profile file
To open the newly created .bash_profile from the terminal, we simply need to type the nano keyword command as follows:
You will see that the .bash_profile file will open in a new window. It has different keys listed at the bottom, with the file name displayed at the top center of the file window.
Edit the .bash_profile file
Now, if you
want to check if any data or information typed in this profile will be displayed in the terminal when calling, you can do so. For that, you need to write some code in the .bash_profile file. Write the echo statement with the ‘FROM BASH_PROFILE’ in quotation marks. Save this file with the Ctrl+S key followed by pressing Y. After that, close this file by pressing Ctrl + X, and you will be navigated to the terminal again.
Now, to implement the changes of this file and verify the result of the written statement in the .bash_profile, we need to write the simple source command
in the terminal as:
You will see that the text written in quotation marks will be displayed in the terminal
To do some additional customization, try a few other things as well. So create a new . bashrc using the touch command and open it using the nano command as:
Scroll down to the bottom and add some echo declaration with some text in quotation marks. Save this file with Ctrl+S followed by pressing the Y key. You can close this file by using the Ctrl+X key.
Now open the .bash_profile again from the terminal using the nano execution command
Note the instructions below in the .bash_profile file. You can avoid hash sign declarations because they are usually comments. In the ‘if‘ statement, ‘-f’ refers to the existence of this file. This means that if the .bashrc file exists, perform the following action. In the next line, the period followed by the listed file name refers to opening this file. Now, save this file using Ctrl + S followed by the Y key. Close it with CTrl+X.
Retry the source command for the .bash_profile file. This will run the .bash_profile file, and obviously run the .bashrc file because the .bashrc file is linked to the .bash_profile file.
Every time you open the terminal, you will see the text displayed in its top corner. This text is written in the .bashrc file because of file linking.
Open the .bash_profile file and set the PATH variable to it, as shown in the image, and export this variable using the export keyword. Save this file and exit.
In the command terminal, type the echo statement followed by the PATH variable. You will see that it will show the different random route locations. These locations are mostly those that have some script file in them. The script file means any login script from which you can update your password.
Therefore, when you add the password command in the terminal, it will display the text as ‘Password Change for Username’. After that, it will ask you for your current user password. So, add your current password. Then, it will ask you for your new password and retype the new password. Through this method, you can change your login credentials for the current user.
Again, open the .bash_profile file using the nano command
Add some additional echo declarations in this file. After that, add another statement that has the initials PS1 followed by =sign. In the quotation marks, add a backslash followed by the alphabet W and greater than > sign. This means that when the .bash_profile file has been executed, it will customize the command terminal by providing space for commands. Save and close this file.
When you run this file using the source command, you will be able to see the text typed in the echo statements as output. You will see another change, which is due to the PS1 declaration. This change is ~> sign, which is used to add new commands.
Now add the cd command followed by double dots in this newly customized terminal. It will direct you to the home directory, which is our established PATH. Again, adding a cd command followed by double dots will direct you to the Linux home file system. When you test the list command in the terminal, it will display the folder list.
Try the cd command followed by the ‘~’ sign and it will direct you to the home directory. When it enumerates the directories, it will display the following output.
In this guide, you have learned how users typically do things like: add some directory to the $PATH variable, export any variable, modify $PS 1, set view colors, add a welcome text message, etc.