Jack Wallen introduces you to aliases to help make your Linux command life a bit simpler.
Sometimes a command is either too long to always be typing out or you simply cannot always remember it. Or maybe you have a collection of commands that you frequently run, and constantly typing them isn’t the best use of your time. When that’s the case, what do you do? You create aliases.
SEE: The best programming languages to learn–and the worst (TechRepublic Premium)
In Linux, an alias is a feature of bash that makes it possible for you to use shorthand for commands. Say, for instance, you have a bunch of servers you frequently SSH into and out of during the day. You could either configure them in the SSH config file or create an even faster alias. So instead of typing the command ssh [email protected] to gain remote access to your web1 server, you could just type web1. How do you do this? It’s all in the .bash_aliases file in your home directory.
Open that file with the command nano ~/.bash_aliases. In that file, you can add as many aliases as you like in the form of alias NICKNAME=’COMMAND’ (Where NICKNAME is the shorthand name for the command and COMMAND is the actual command to run).
So, let’s stick with our SSH example.
- For that, you’d 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 will take effect. Once you start a new terminal, you can simply type web1 to run the command.
And that’s all there is to creating an alias for a command on Linux. Get really creative with this, and your command-line work in Linux will become much more efficient.