Jack Wallen introduces you to aliases to help simplify your Linux commands a bit.
Sometimes a command is either too long to always be typed, or you just can’t always remember it. Or maybe you have a collection of commands that you run frequently, and typing them constantly isn’t the best use of your time. When it does, what do you do? You create aliases.
SEE: The best and worst programming languages to learn (TechRepublic Premium)
On Linux, an alias is a feature of bash that allows you to use shortcuts for commands. Suppose, for example, that you have a bunch of servers that you frequently connect to using SSH during the day. You can either configure them in the SSH configuration file or create an even faster alias. So instead of typing the command ssh [email protected] to remotely access your web1 server, you can simply type web1. How do you do that? Everything is in the .bash_aliases file in your home directory.
Open this file with the command nano ~ / .bash_aliases. In this file you can add as many aliases as you want in the form of alias NICKNAME = ‘ORDER’ (Where NICKNAME is the short name of the command and COMMAND is the actual command to be executed).
SEE: C ++ Programming Language: How It Came The Basis Of Everything And What’s Next (Free PDF) (TechRepublic)
So, let’s stick with our SSH example.
- To this you would add alias = web1 = ‘ssh [email protected]’.
- Save and close the file.
Now here’s the trick: you need to close that terminal window before the new alias takes effect. Once you start a new terminal, you can just type web1 to execute the command.
And that’s all there is to creating an alias for a command in Linux. Get really creative with it, and your Linux command line work will become much more efficient.