If you are a Linux user, you might be aware that, unlike Windows operating systems, most of the work here is done using the commands. This system of commands seems a bit tricky initially, but once you have been using Linux servers or Linux operating systems for a long time, you easily get familiar with the system of commands you use in Linux.
Speaking of Linux, one of the systems here is Bash which comes with many other shells inside it like korn, csh, dash, and more. When you are doing anything related to this shell in Linux, there are some commands, out of which some are used to access the .bashrc files.
A brief introduction to Source .bashrc file
Before jumping right into the Source .bashrc file, you must know a little about the background. Speaking of the backgrounds here, the important thing is the shell.
What is a shell in Linux?
So, a shell is an interpreter. It takes the commands from the users and runs those commands. Those commands from the users are run to perform all the actions and operations like navigating around some file system, using the devices, or running several programs.
As Bash is a shell that you use in Linux, several files and other shells come under its name. One of the files is the .bashrc file, and in most cases, there could be more than one of these. So, you can open the terminal in Linux and type the following command:
“find / -name .bashrc”
When you run the .bashrc command in the terminal window on Linux, you will be copying the .bashrc file on the home folder. Interestingly if there is more than one user, then the file will be copied for all of those. One thing that this command will return is home/user1/.bashrc.
It is the file that will be used whenever user1 opens a shell. Similarly, the root file will be used whenever the root opens the shell.
What is the Source .bashrc file?
It is a shell script that runs whenever any user opens a new shell on the system. You can run the following command “Source ~/.bashrc.” The interesting part is that sometimes it provides some display and sometimes not, but it runs most of the time automatically.
It is usually triggered by some event happening in the system, like running the shell or opening the terminal, or even reloading the .bashrc file manually.
Source .bashrc file location
Speaking of the location of the Source .bashrc file, it is a good place in the Linux system. So, when you need to run the .bashrc command, you open a shell every time. There are several ways to run the .bashrc command, and some of them are mentioned below:
Open the Source .bashrc file as nano
You can use the following command to run the .bashrc file using nano: “nano `/.bashrc.” When you run this command, you will see some files. At the end of that file, you can enter the following command: “echo HELLO $USER.” Once you do this, you need to save and then exit from here. You can also use it by pressing the “Ctrl + O” and “Ctrl + X” combinations on your keyboard.
Once you are done saving and exiting the file, you need to go to the terminal window on your system and type in the following command: “source ~/.bashrc.” Run this command, and you will see “HELLO” printed on the screen. Not only this, but there will be the username of the current user printed along with hello.
Source .bashrc file debug
The .bashrc file is vital and very powerful in the Linux operating system, and you can do anything in the system you want to do. Let us take an example of doing anything that you do with the Source .bashrc file in Linux.
Checking the system information
One of the most common examples here is neofetch. It displays the whole important system information, and people usually use it as a terminal login message.
So, if you are looking to try using the Source .bashrc file here, you need to follow the steps we show here.
- The first step will be installing the neofetch on your Linux system. You can easily do it by running the following command in your terminals: “sudo apt install neofetch”. Once you are done with the installation of neofetch you can add it to a line in your Source .bashrc file. Here you can call it Neofetch, and doing it only requires you to run the following command: “neofetch.”
- The next thing you need to do here is to reload Bash, and you will be done. For doing so, you need to run the following command: “source ~/.bashrc.”
As soon as you run the last command in the terminal, you will see all the special information about the system, and some type of image printed with characters will also be printed on the screen.
Another amazing thing that you can do using the Source .bashrc file and the bashrc script command is to set the aliases for the longer commands. It is usually used for the commands that are hard to remember, and those are often used. So, the bashrc script can be used for setting and using aliases on your system with ease.
If you are looking to make an alias for the command that provides the list of files and directories present on your system, then you can run the command: “alias listcols=`ls -A -CF`.” Here “-A” will be the alias, and the “-CF`” will be the classification of the list, and in this way, you can create aliases for any commands in Linux.
Although the Linux operating system is not as easy to use because of the commands, you can use several commands to control the system. Commands like bashrc script are very powerful as they allow you to do a lot of cool things and customizations.