Creating Aliases in GNU / Linux

There is a very simple way to customize and make easier some commands that we normally use in "the console", Through the use of Alias.

Un Alias as its name indicates, it will help us to replace a word or series of words with a shorter and simpler one. Let's take a practical example, let's say we want to see the logs from the system, using an application called Colorizer which is responsible for coloring the result on the console. The line would be:

$ sudo tailf -n 5 /var/log/syslog | ccze

But I'm sure it would be easier if instead of writing all that, we put in the console for example, something as simple as:

$ syslog

True? It would be much more comfortable and easy to remember. Then, how do we do it?

Creating an Alias.

Creating an alias is really easy. The syntax would be:

alias short_word = 'command or words to replace'

if we take the previous example it would be:

alias syslog = 'sudo tailf -n 5 / var / log / syslog | ccze '

The command is enclosed in single quotes. But the question is Where do we put this? Well, if we want it to be only temporary, we simply write it in the console and it will last until we close it.

Now, if we want it permanently, we put this inside the file ~/.bashrc which is in our / Home, and if it is not, then we create it (always with the dot in front). When we have added the line of the alias In this file, we simply put in console:

$ . .bashrc

And ready!!!

Note: Yesterday due to problems with our ISP we could not publish anything in <° Linux, for which we apologize


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

7 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Jc said

    This type of post does not hurt to refresh those tools that we do not usually use on a daily basis. Also, it is timeless; three years after writing it and it remains as the first day.
    Add that, at least in debian, it is recommended to make use of the .bash_aliases file to add your own aliases instead of the file you mention. He . .bashrc takes care of searching the alias file I say.

  2.   Victor said

    Thanks for the tutorial. I have a question: what does the command '. .bashrc '? and in particular what does the dot (.) in front of the .bashrc file do?

    1.    Sicker said

      I know it's too late, but a dot in front of a filename causes it to be hidden in folders, so it will be there, but you won't be able to see it until you show the hidden files.

      1.    alohl669 said

        I don't think it refers to the point of hiding files. If you look closely there is another one separated by a space before:
        $. .bashrc

        At first I thought that it would somehow run the file or reload the information it contains. Instead, I had to reboot for the aliases to take effect, so the command remains unknown.

  3.   johndry said

    How can you continue to use a command even though there is an alias that refers to this command? (Example: how would you use the rm command if this is an alias to echo?)

  4.   Pablo said

    Very grateful for this. Cheers!

  5.   alexredondosk8 said

    Hello, thank you very much for the tutorial, it helped me a lot.