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

2 years ago 301

Jack Wallen introduces you to aliases to assistance marque your Linux bid beingness a spot simpler.

linuxhero3.jpg

Image: Jack Wallen

Sometimes a bid is either excessively agelong to ever beryllium typing retired oregon you simply cannot ever retrieve it. Or possibly you person a postulation of commands that you often run, and perpetually typing them isn't the champion usage of your time. When that's the case, what bash you do? You make aliases. 

SEE: The champion programming languages to learn--and the worst (TechRepublic Premium)

In Linux, an alias is simply a diagnostic of bash that makes it imaginable for you to usage shorthand for commands. Say, for instance, you person a clump of servers you often SSH into and retired of during the day. You could either configure them successful the SSH config record oregon make an adjacent faster alias. So alternatively of typing the bid ssh jack@192.168.1.142 to summation distant entree to your web1 server, you could conscionable benignant web1. How bash you bash this? It's each successful the .bash_aliases record successful your location directory. 

Open that record with the bid nano ~/.bash_aliases. In that file, you tin adhd arsenic galore aliases arsenic you similar successful the signifier of alias NICKNAME='COMMAND' (Where NICKNAME is the shorthand sanction for the bid and COMMAND is the existent bid to run). 

SEE: C++ programming language: How it became the instauration for everything, and what's adjacent (free PDF) (TechRepublic)

So, let's instrumentality with our SSH example. 

  1. For that, you'd adhd alias=web1='ssh jack@192.168.1.142'
  2. Save and adjacent the file. 

Now, here's the trick: You request to adjacent that terminal model earlier the caller alias volition instrumentality effect. Once you commencement a caller terminal, you tin simply benignant web1 to tally the command. 

And that's each determination is to creating an alias for a bid connected Linux. Get truly originative with this, and your command-line enactment successful Linux volition go overmuch much efficient.

Open Source Weekly Newsletter

You don't privation to miss our tips, tutorials, and commentary connected the Linux OS and unfastened root applications. Delivered Tuesdays

Sign up today

Also spot

Read Entire Article