Hi guys, today I will show how easy it is to set up aliases in almost any Linux distro. Before we begin let's clarify what are aliases in the bash.
Alias is a command that enables replacing a word or set of letters with a bash command. Often it is used for simplifying the workflow in the command line, for example, we can come up with an abbreviation that is going to equal multiply commands. Without further due let's hop into the setup process.
To create an alias there are 3 easy steps:
1. Navigate to your home directory.
To navigate to your home directory using the cd command.
cd /home/your_username
2. Add your alias to the .bashrc file.
After you have navigated to your home directory, open the .bashrc file with nano.
sudo nano .bashrc
Now go to the bottom of the file and type alias, then the name of the custom command and the Linux commmand/s it represents. Take in mind that there are no spaces between the equal sign, otherwise it is not going to work.
You can add as many custom commands as you want. Every command should be on a new line. After you are done, save the file and exit.
3. Activate the custom commands you've added.
Probably you have noticed after saving the file when you try to run a custom command it doesn't work that is because we have not activated them yet. To activate just type in the command line source and .bashrc.
source .bashrc
And you are ready! Now you can run any of the custom commands you have created
If you have any questions, comment them down I will answer them as soon as possible.
Top comments (4)
Two important edits:
Combine steps one and two. There's no reason to separate them:
For step #3:
.
should be introduced to readers, notsource
. Thesource
command is a bashism and should be avoided in favour of.
so that readers gain a more generalized and useful knowledge.Clarify that alias expansion is not standard POSIX and only works for bash in conjunction with the
shopt -s expand_aliases
bash option (which happens to be enabled by default). It's safe if you follow your steps because only bash will read~/.bashrc
, but I and some other people take examples from posts we read and apply them elsewhere, so this is important notice.Thank you very much for your feedback. I will take it into account.
๐ฅYou are super guy!๐ฅ Go ahead! ๐
Thank you very much! Glad you liked my content. โค๏ธ