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
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.
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?
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.
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.
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?)
Very grateful for this. Cheers!
Hello, thank you very much for the tutorial, it helped me a lot.