How to Set Up Command Aliases in Linux/Ubuntu/Debian

Aliases are one of the most time-saving devices. An alias is a way to make a complicated command or set of commands simple. This is best demonstrated by an example.

In web development or computer programming, there are a lot of times we need to recompile some source file. Below we are recompiling a less file and looking at the tail of the result.

Note: The example below can be generalized to any set of commands.

cd /home/myuser/public_html/less/                                                                                                              lessc -c style.less > ../style.csscd ../

Steps to Setting Up Aliases in the bash-shell

Wouldn’t it be easier to just type something like the following?

tailmyless

Luckily for us, this is simple to do in the bash-shell.

1. Open .bashrc

Our  .bashrc file is located in our user directory. Open it in text editor.

$ vim ~/.bashrc

2. Go to the end of the file

In vim, we can accomplish this just by hitting “G” (please note that it is capital).

3. Add the alias

A simple way to chain commands in Linux is to use the && operator. This operator will run a set of commands and only continue to the next command if the previous one was successful. For our example, we might have an alias that looks like this:

aliastailmyless='cd /home/myuser/public_html/less && lessc -c style.less > ../style.css && cd ../ && tail style.css'

This looks complicated but it really isn’t.  Here’s the basic format:

alias aliasname='commands'

There cannot be a space between the “aliasname” and the EQUAL sign. Also, there can’t be a space between the EQUAL sign and the opening quote for the command.

4. Write and close the file

In vim, hit ESCAPE to get to normal mode and run the following command to write and quit:

:wq

5. Install the .bashrc

The new .bashrc would be installed the next time we log out and log back in, but if you are impatient like me and just want it installed now, you can just source the file.

$ source ~/.bashrc

Well, that’s it. Now we can alias until our heart’s content. Remember, a few seconds saved here and there can dramatically increase our efficiency!



Was this article helpful?

Top Related Jobs

Top Freelance jobs are waiting for you, View & apply to earn more.

  • Connecting web server to database server

    $10, Hourly | India
    I need to connect my centos 6 web server to my centos 7 database server. I have SELinux enabled and i think we need to configure the iptables firewall...
  • Server Management, Maintenance and Monitoring

    $28, Hourly | India
    We are looking for a freelancer to manage, maintain and monitor Linux server. The software resides inside the server is a fleet management software, i...
  • Linux Help Needed for Mongo Investigation

    $28, Hourly | United States
    We are looking to downsize some Mongo instances. In order to do that, we need some Linux help to track down the following information:-Track down how...
  • Looking For SBO Solution Voip

    $300, Fixed | Singapore
    Hi, i am looking for SBO solution for voip, which can be build with Asterisk (PBX).I will share some refernce link with shortlisted candidatesPlease l...
  • How to warm up shared IP using PowerMTA

    $20, Hourly | Brazil
    I am looking for an MTA Operations Expert with experience using POWER MTA. I do not require the expert to do any IP warming, just produce a document t...
  • Decrypt PEDANT file (ransomware)

    $50, Fixed | United Kingdom
    My files was encrypted by Pedant ransomware, MYID.PEDANTplease if you can help me to recorver my important files will be great.
  • OpenSips Load balancing for Asterisk 4 Instances

    $20, Fixed | Italy
    I need someone who can enable/configure incoming calls load balancing on OpenSips among 4 Asterisk instances, I will share my current opensip conf wit...


People also searched for

Understanding chatbots and how to build one simple chatbot in Python
Understanding chatbots and how to build one simple...
Other - Software Development

A chatbot is an artificial intelligence powered piece of software in a device, application, web site or alternative networks that try to complete consumer’s needs and then assist t...

Read More
How to solve non-linear optimization problems in Python
How to solve non-linear optimization problems in P...
Other - Software Development

Optimization deals with selecting the simplest option among a number of possible choices that are feasible or do not violate constraints. Python is used to optimize parameters in a...

Read More
Why freelance job is better than full time job
Why freelance job is better than full time job
Other - Software Development

A large number of people think that “freelancing” is something you do when you cannot get a real job. On the other hand, “freelancers” know that there is nothing more real than tha...

Read More

You are freelancing Ninja?

Try Toogit Instant Connect today, The new virtual assistant for your freelancing world.


What our users are discussing about Linux