Skip to main content

Improve your Efficiency in Linux using "Alias" command

Have you ever tried to make a custom  command in Linux that can do a specific function.
Fear not today we are going to look at how we can do that and increase our efficiency in Linux using the "alias" command

What is an alias in Linux

So,normally we have to use Linux commands frequently and typing the same commands over and over again can reduce efficiency .And that is one of the reasons we use the aliases


List currently defined Aliases in Linux


You can see a list of defined aliases on your profile  by simply executing the alias command and it will do the magic.


here you can see the default aliases for the Linux systems.

How to create Aliases in Linux.

Create temporary Aliases:

        alias alias_name='command'

here is an actual example

        alias la='ls -alh'




What you need to do is type the word alias then use the name you wish to use to execute a command followed by "=" sign and quote the command you wish to alias.

If you open new terminal session, the alias will no longer be available. If you wish to save your aliases across sessions you will need a permanent alias.

*point to note is not to use the predefined words in the Linux command and to know the predefined commands just type help in the terminal and you will see every word that you cannot use in your aliases

help

Creating Permanent Aliases.

There is a file named "bashrc" (a hidden file) in you home directory.The bashrc file is shell configuration file and it will run everytime a shell session starts.

The shell configuration can be different it can be either of this:
       
  • Bash – ~/.bashrc
  • ZSH – ~/.zshrc
  • Fish – ~/.config/fish/config.fish

So, in order to make an alias permanent we need to put them in bashrc file in user home directory.
you can open the bashrc with your favorite editor like for my case i will use vim

    vim .bashrc   

remember this is in your home directory

 
Look for the place where is some more alias commands and just add your commands there and that is  it, do not forget to save.for the other commands that you have seen in bashrc file you can just remove the comment and they will be active


Storing Aliases in the .bash_aliases File

The ".bash_aliases" file will not exist till you create it so you will heve to create it with the following command

        touch .bash_aliases


Now we can edit the file and add our aliases commands



    vim .bash_aliases


we have added some aliases.The first is cl  is to clear our terminal the next is h to call the history command and the last is smokelicity to upgrade the system.


To remove an alias added via the command line can be  unaliases usind unalias command

        unalias alias_name
        unalias -a [ remove all alias ]

Conclusion

This was a short and the simplest way to create your own alias and execute frequently used commands without having to type the commands again and again.

Comments

Post a Comment

Popular posts from this blog

What are browser cookies and how they work

INTRODUCTION. Most internet users are familiar with the term Cookie because we see it pop up in most websites but do we know the purpose it serves. Let us start with what it is ,   a cookie (  also known as browser cookie , internet cookie , web cookie or HTTP cookie ) is small piece of data that websites store on your disk in the form of a text file.Cookies allow websites to store specific information helpful to remember each visitor uniquely. What do browser cookies do. The purpose of the computer cookie is to help the website track of your visits and activity and is not a bad thing.A good example are the online retailers to keep track of the items in user's shopping cart as they explore the site, without the cookies the shopping cart would reset to zero with every click. A website also uses the cookies to store information about you recent visits or record you login information which i do not really recommend from a security perspective Types of browser cookies. Session co...

What is session hijacking and how to prevent it.

What is session hijacking Session hijacking is a type of web attack where an attacker takes advantage of an active session.The attack relies on the knowledge of your session cookie, so it is also called cookie hijacking or cookie side-jacking. Although any computer session could be hijacked, session hijacking most commonly applies to browser sessions and web applications. In most cases when we log in web applications, the server always sets a temporary session cookie in your browser to remember you are currently logged in and authenticated. For an attacker to perform session hijacking, he or she needs to know your session id.This can be done by stealing the session cookie or by persuading the user to click on an malicious link.In both cases the attacker can take over the session by using the same session id on his own browser session.And with that  the server has been fooled into treating the attackers session to be the original valid connection. What are the main methods of Sess...