Today's guide covers a very useful topic, creating aliases in bash. The use of aliases increases the efficiency of using the terminal and is helpful for those who don't remember the infinite options of some commands. We will conclude the article with an introduction to the functions.
Bash alias: what they are and how to create them
I don't know about you, but my favorite terminal command is history. My very low memory combined with atavistic laziness often and willingly leads me to rely on the historical memory of the various terminals that I use, rather than the countless posts attached almost everywhere between home and office. If you are also a club member, then bash aliases are for you.
This instruction allows you to create a shortcut, to which to associate a complex instruction. This allows to significantly increase the efficiency of the use of the terminal. And this, especially in all those situations in which we often use long and repetitive commands, is very useful.
Let's see how to proceed with their creation. We open the configuration file as follows:
nano ~/.bashrc
The syntax is very simple. As can be seen from the screenshot, first of all, we need the keyword, followed by the name of our shortcut and finally by the command we want to shorten, assigned as a string in quotation marks. All that is preceded by a hash is a comment. We can, for example, create the alias II which replaces the ls -alF command.
After making the changes, let's make them persistent by giving, from the terminal, the command:
source ~/.bashrc
Bonus: the functions
Let's increase the level of complexity a little bit, with the promise of a more detailed treatment of the topic in a future guide. A bash function is nothing more than a set of instructions, which can be called by the user. These can always be added to the bashrc file using the following structure:
nome_funzione ( ) {
. . .
istruzioni
. . .
}
This function basically renames the photo using the second $2 argument we pass it, and reproportions it 1400*something.
0 Comments