Also Read: Best Linux Server Monitor Tools & Softwares
One of the most frequently used aliases is ll which will be set to run “ls –lha” or something similar. That will display the most details about files, revealing hidden files, and show file sizes in units that are readable to us. You can also utilize this command for creating shorter versions of codes or forcing a code to always run with your favored flags, or even guard against common typos. You can also circumvent annoying or easy-to-forget syntax with your preferred shorthand. A list of defined aliases on your profile will display by simply executing the alias command:
alias
The output of this command will display the default aliases defined for your user in Ubuntu 18.04 as shown in the following picture:
As you can see, $ ll Is equivalent to running $ ls –alF. You can also create your temporary aliases. To do so, Type the alias word. Then, use the name you wish to use for executing a command that is followed by the = sign and quote the command you want to alias. The syntax is something like this:
alias shortName="your custom command here"
For example:
alias wr="cd /var/www/html"
You can then use this shortcut to go to the webroot directory. However, it has one problem. This is only available for your current terminal session, and if you open a new terminal session, the Alias will no longer be available. So, if you wish to save your Aliases, you require a permanent Alias.
So far, we have discussed multiple ways you can benefit from using the .bashrc file in Linux. Now we can get familiar with the steps you need to take for opening bashrc and saving a file, guiding you to use the most out of Linux bashrc.
Also Read : What is Netcat Listener and how to use it?
How to Open Bashrc and Save a File?
The syntax you should use is practically the same as creating a temporary alias, except this time, you also have to save it in a file. So:
Step 1: Open a .bashrc file in a sample bash like the following:
vim ~/.bashrc
Step 2: Find a place for Aliases file
Find a place in the file where you intend to keep the Aliases. For instance, you may want to add them at the end of the file.
Step 3: Save the file.
After that, This file will automatically load in your next session.
Note: the unalias command will use for removing an alias.
unalias alias_name
unalias -a [remove all alias]
In addition to using bashrc for various prompts, you may need to know how to modify the .bashrc files, which we will explain in the following.
How to Edit .bashrc files?
You may want to add your own commands in any terminal text editor. To do so, you can edit bashrc. We will use a nano editor in the following examples.
Step 1: To edit bashrc through nano, type the following command in Terminal:
nano ~/.bashrc
Note: If it is the first time you are editing your .bashrc file, you might find that it is empty. That is not a problem. If not so, you can feel free to put your additions on any line.
Remember that any changes you make to .bashrc will apply next time you launch the terminal. If you want to make use of them immediately, run the command below:
source ~/.bashrc
Step 2: Wherever you wish, you can add to your .bashrc file. Nevertheless, it is better to use a command (proceeded by #) for organizing your code.
Note: Bring in mind that edits in .bashrc must follow bash’s scripting format. If you do not know how to script with bash command, then use online resources.
How to Reload bashrc File?
If you intend to reload the bashrc file without opening a new file, run the following command:
~/ .bashrc
As you know, the dot operator will execute this command from the file in the current environment. You can also use the source command as shown below:
Source ~/ .bashrc
What is bash_profile?
Every time you create a new bash session, a file for the bash profile will create. This is a file named .bash_profile in the home directory of your computer that bash runs. To create your bash file, run the following command:
sub1 ~/ .bash_profile
The tilde (~) is equivalent to /User/Rich and tells bash to start traversing the file system from the home directory. It means, you can write the previous command in the following format:
Sub1 /Users/Rich/.bash_profile
But utilizing the (~) is a shortcut that is useable for every user to understand.
Where is bash_profile?
You may ask where the bash_profile path is. bash_profile is a hidden file located in the home folder, and you have to make it visible. If ~/ .bash_profile does not exist, ~/ .profile is located instead.
Bashrc vs. bash_profile
.bashrc is only sourced in interactive mode when bash does not act as a login shell. On the contrary, .bash_profile is only sourced as a non-interactive shell with the – login option or when bash started as an interactive login shell. It means it is suitable for commands that should run once, while bashrc is great for commands that you should run in every new shell.
Want a better way to host your websites and web apps? Developing something new? Simply don’t like Windows? That’s why we have Linux VPS.
Get your Linux VPSFinal thoughts: Linux bashrc
This article gave you a brief description of Linux bashrc and how you can utilize it. Of course, there is more to know about this topic, the limitation of .bashrc is your imagination or coding skills, but with our quick and easy-to-use guidelines, you should be able to do all the basic things we have mentioned about .bashrc. Additionally, you can use our Linux VPS solutions to help you get the best experience in using Linux. Our KVM-powered Linux VPS plans are designed to give you multiple benefits, including significant bandwidth, guaranteed uptime (99.95%), ultrafast SSD storage, reliable connection, and 24/7 technical support, among other advantages. So do not delay this further and get a cheap Linux VPS at $7.95. If you have any further questions we did not cover, leave us a comment, and we will try to write back as soon as possible!
FAQ
What is .bashrc file?
A bashrc file is a shell script that Bash executes whenever it is initiated. The bashrc helps specify how your command-line interface (CLI) or Terminal app looks and acts, Along with setting in the OS.
What is a bash_profile in Linux?
bash_profile is used to customize the user configuration settings and is a file, mostly hidden, located in the home directory. Additionally, bash_profile files are configuration scripts that include variable specifications, export variables, and login commands like mail or news search.
Why is it called bashrc?
In bashrc, the term rc stands for the phrase “run commands”.
Where is bash_profile in Linux?
bash_profile is located under every user home directory in which every user may have different bash configurations.
Thank you I exactly found what I was looking for in your article
I have started to like linux bash but since I am a windows user is there a way for me to use it? I don’t know any software that would act like Linux Bashrc or anything else?
You can use Bash on Windows with a Windows subsystem that Ubuntu Linux runs it. That subsystem is not a virtual machine or an application like Cygwin. It’s a comprehensive Linux system inside your Windows 10 machine. Basically, it lets you run the same Bash shell that you find on Linux.
Thank you so much for taking your time to read our blog 🌻
Thank you for this complete tutorial
I think everyone who is using Linux OS should know about Linux bashrc and how to use it. It is really powerfull and usefull
Thank you for covering a topic about .bash_profile in your article. I had no idea about this file
I had read your article about 3 months ago and it was lacking something like .bash_profile. And now that I randomly checked this article I see that you have implemented that topic into the article. Thanks for the great work
Linux Bashrc is one of the most interesting parts of linux. Anyone who is not using Linux and its great features, it is their loss
Without a shell, one can hardly use the functions of the kernel installed on their system. Bash Shell configuration files (such as .bashrc and .bash_profile) allow us to customize the Shell experience as needed
There is something that I can’t really figure out. How linux bashrc is different than Linux terminal?
Thank you so much for taking your precious time to read our blog 🌻
Bash_profile is read and executed when Bash is invoked as an interactive login shell, while bashrc is executed for an interactive non-login shell. Bash_profile runs commands that must run only once, such as customizing the $PATH environment variable.
The whole thing about a .bashrc file is to create an area wherever you have created variables, functions and aliases, outline your prompt and define different settings that you simply wish to use when you open a brand new terminal window. It works by being run each time you open up a new terminal, window or pane.
How to define a function in linux bashrc? And also I wonder if there is a way to customize terminal
Great article. You literally covered everything about Linux that I was looking for on the Internet
Wow I am new to linux these commands really work!😎
m not sure where you’re getting your info,
but great topic. bash_profile vs .bashrc? what is the different?
When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to piece your shell before the initial command prompt.
But, if you’ve already logged into your machine and open a replacement terminal window (xterm) then .bashrc is executed before the window command prompt. .bashrc is additionally run once you begin a new bash instance by writing /bin/bash during a terminal.
On OS X, Terminal by default runs a login shell each time, so this is often a bit completely different to most alternative systems, however you can piece that within the preferences.
I know this web page gives quality depending articles or reviews and
extra stuff, therefore Do ou know How to stop a running Bash script or command?
To exit from bash type exit and press ENTER . If your shell prompt is > you’ll have typewritten ‘ or ” , to specify a string, as a part of a shell command however haven’t typed another ‘ or ” to shut the string. To interrupt the present command press CTRL-C .
What is bashrc file location in Linux of other distros? Is there a difference?
Thanks for a great question. No, the bashrc file (.bsharc) is in the same location in all distros. So, if you’re wondering about Linux .bashrc_where is bashrc file Linux, you can just read the guide and you’ll have your answer.
Hey guys. I have seen two questions around the web and I want to know if they are different: “what is bashrc file in Linux” and “what is .bashrc file in Linux”?
Hi there. Actually, they’re the same question. Sometimes, the bsharc file is written as .bashrc so that’s why sometimes you see “what is bsharc” and sometimes “what is .bsharc” in forums.
Is the Linux bashrc_.bashrc file in Linux the same as the bashrc file in FreeBSD?
There are some similarities, of course, since both Linux and FreeBSD are Unix-like operating systems, but they are also very different.