Site icon TechNewsBoy.com

Linux 101: What are aliases and how do you use them?

Jack Wallen introduces you to aliases to help make your Linux command life a bit simpler.

Image: Jack Wallen

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 jack@192.168.1.142 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). 

SEE: C++ programming language: How it became the foundation for everything, and what’s next (free PDF) (TechRepublic)

So, let’s stick with our SSH example. 

  1. For that, you’d add alias=web1=’ssh jack@192.168.1.142′
  2. 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.

Also see

For all the latest Technology News Click Here 

 For the latest news and updates, follow us on Google News

Read original article here

Denial of responsibility! TechNewsBoy.com is an automatic aggregator around the global media. All the content are available free on Internet. We have just arranged it in one platform for educational purpose only. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials on our website, please contact us by email – abuse@technewsboy.com. The content will be deleted within 24 hours.
Exit mobile version