Set Command Aliases Linuxubuntudebian

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

Written by: Ryan Frankel

Ryan Frankel

Ryan began developing websites in the late '90s and has personally tested just about every web host and cloud platform worth trying on the market today. With a masters degree in electrical and computer engineering from the University of Florida, he leverages his extensive knowledge of hardware, software, and their engineering relationship to inform HostingAdvice readers of the technical implications of their hosting choices. Ryan's subject matter expertise includes, but is not limited to, WordPress, cloud infrastructure management, product UI/UX design, and popular web development languages such as JavaScript and PHP.

See full bio »

Edited by: Lillian Castro

Lillian Castro

Lillian brings more than 30 years of editing and journalism experience to our team. She has written and edited for major news organizations, including The Atlanta Journal-Constitution and the New York Times, and she previously served as an adjunct instructor at the University of Florida. Today, she edits HostingAdvice content for clarity, accuracy, and reader engagement.

See full bio »

If you don’t know how to set up aliases in Linux, you should be very happy you have reached this page! Aliases are one of the most time-saving devices known to man. 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 you 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 your .bashrc.

Your .bashrc file is located in your user directory. Open it in your favorite text editor.

$ vim ~/.bashrc

2. Go to the end of the file.

In vim, you 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:

alias tailmyless='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'

One gotcha is that 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 you 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. You now can alias until your heart’s content. Remember, a few seconds saved here and there can dramatically increase your efficiency!

Advertiser Disclosure

HostingAdvice.com is a free online resource that offers valuable content and comparison services to users. To keep this resource 100% free, we receive compensation from many of the offers listed on the site. Along with key review factors, this compensation may impact how and where products appear across the site (including, for example, the order in which they appear). HostingAdvice.com does not include the entire universe of available offers. Editorial opinions expressed on the site are strictly our own and are not provided, endorsed, or approved by advertisers.

Our Editorial Review Policy

Our site is committed to publishing independent, accurate content guided by strict editorial guidelines. Before articles and reviews are published on our site, they undergo a thorough review process performed by a team of independent editors and subject-matter experts to ensure the content’s accuracy, timeliness, and impartiality. Our editorial team is separate and independent of our site’s advertisers, and the opinions they express on our site are their own. To read more about our team members and their editorial backgrounds, please visit our site’s About page.

ABOUT THE AUTHOR

Ryan Frankel has been a professional in the tech industry for more than 20 years and has been developing websites for more than 25. With a master's degree in electrical and computer engineering from the University of Florida, he has a fundamental understanding of hardware systems and the software that runs them. Ryan now sits as the CTO of Digital Brands Inc. and manages all of the server infrastructure of their websites, as well as their development team. In addition, Ryan has a passion for guitars, good coffee, and puppies.

« BACK TO: HOW-TO
Follow the Experts
We Know Hosting

$

4

8

,

2

8

3

spent annually on web hosting!

Hosting How-To Guides