• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How to Use a Bash Alias in Linux

Bhagwad Park

Published on: February 12, 2025

Categories: Linux Command Line, VPS Hosting 0

When you first start using Linux, you’ll need only a handful of commands. As you gain experience, you learn more of them, but the complexity of the commands increases. Commands like awk, df, git, etc., all have a huge range of options and endless combinations of them. Every Linux system administrator and every server has its own peculiarities. The commands that work for you won’t feel natural for someone else, so you develop your style, workflow, and way of doing things. With such specificity, comes complexity, and you should know how to use the bash alias to streamline this.

Table of Contents
  • What is a Bash Alias?
    • Saving Time for Repetitive Commands
    • Reducing Errors and Increasing Safety
    • Improved Readability
  • How to Create Aliases in Bash
  • Making the Aliases Permanent
  • Can’t Use Aliases with Dynamic Arguments
  • Conclusion

What is a Bash Alias?

A bash alias is a substitute for a command. You can use it to substitute commands of arbitrary complexity. While the basic “alias” command doesn’t support arguments, you can create aliases using functions instead. I’ll show you how to create both. Here are the main benefits of aliases.

Saving Time for Repetitive Commands

There are many commands that you use a lot but can be a pain to type. For example, everyone uses “ls” to list the contents of a directory, but you often want to see everything, including hidden files, and see all the permissions and space used by each file in a human-readable format. The command for doing this is:

ls -lah

Not too hard to type, of course, but nowhere near as easy as simply “ls”. And that’s an easy example. Some statements involving grep or awk can become incredibly complicated with special characters, curly brackets, and more. Using an alias is a great way to save time and replace a complex command with a simple one.

Reducing Errors and Increasing Safety

Complex commands can include typos, which fail the command. Long commands with special characters are particularly vulnerable to this. But the command failing is the least of your worries. The worst that can happen is you feel frustrated and have to find and correct the mistake.

Far more dangerous are those commands where a typo can result in disastrous consequences. For example, commands like “cp” and “mv” will quietly overwrite any files with the same name. For this reason, we often use these commands with the “-i” flag, like this:

cp -i filename.txt

The “-i” asks for confirmation if you try and overwrite a file. But it’s possible to forget this argument. Or maybe someone new is using your server and they don’t have the caution to use the “-i” flag each time. This could result in a disastrous wipeout of an important file.

An alias can enforce the usage of the “-i” flag by redefining the “cp” command to always include it.

Improved Readability

Using an alias can greatly improve the readability of a complex command. For example, take the following git command:

git log --oneline --graph --decorate --all

This will show a neat, visual representation of the commit history. But who is going to sit and type all this each time – particularly if it’s a commonly used command? Not to mention it’s easy to forget to include a particular flag. It’s far easier to create an alias with a clean name that can replace this.

For all the above reasons, an alias is one of the most powerful tools in the arsenal of an experience Linux administrator, and it allows them to customize the shell to their own unique needs.

Now let’s see how we create these aliases.

How to Create Aliases in Bash

To create a bash alias, we simply use the following command:

alias shortname='command'

So for example, to create an alias of the “ls -lah” command I showed earlier, we just use:

alias ll='ls -lah'

After you run the above command, you can just type “ll” and it’ll expand to the full command. Here’s how it looks:

Bash Alias
Bash Alias

As you can see, if this is a command that you use often, then having an alias makes your job much easier.

You can also use aliases to chain commands together. In Linux, often you use multiple commands one after the other in quick succession. For example, when you’re installing a new package, you always want to ensure that you have the latest repository information. This means you should both “update” and “upgrade” the repos one after the other. Typing out both these commands each time is annoying, and you can use an alias like this:

alias update='sudo apt update && sudo apt upgrade -y'

Here’s how it works:

Using Aliases to Chain Commands
Using Aliases to Chain Commands

So with this alias, you can just type “update”, and the command will execute. See how much easier this is than typing out commands one after the other! As a bonus, you won’t have to wait before the first command is done before moving on to the next since they’ll start automatically one after the other.

Making the Aliases Permanent

Unfortunately, when you create a new alias in Linux as shown above, it’s only temporary. The aliases will vanish once you exit and restart the shell. This is by design – the temporary aliases are stored in working memory and aren’t written in the shell configuration. If you want your definitions to persist, then you must write the changes into the following file:

~/.bashrc

The above file is the place where you can place all the custom configurations for the current shell. You can open this file for editing using the following command:

vi ~/.bashrc

Here’s what the contents of ~/.bashrc look like:

Contents of .bashrc

As you can see, I already have some aliases defined such as “ll” for “ls -la” and I’ve redefined “ls” to include the “–color=auto” flag. If you have additional aliases, make sure you add them to this file and save your changes.

But there’s one more step. The changes to the ~/.bashrc file will take place when you restart your shell – they won’t be applied automatically to the current shell. If you want this to take effect immediately, you can use the “source” command like this:

source ~/.bashrc

This will apply the changes, and you can start using the aliases defined in .bashrc.

Can’t Use Aliases with Dynamic Arguments

While you can use an alias with static arguments that work when the command is fully expanded, it doesn’t work with dynamic arguments. For example, let’s say I want to search all “txt” files for a word. The regular command I use is:

grep "[word]" *.txt

Now I try and create an alias for a new command like this:

alias mygrep='grep $1 *.txt'

The hope is that I can type:

mygrep hello

Unfortunately, this won’t work, because the “alias” command will simply expand blindly and won’t replace $1″ with “hello”. To work around this, we can use a function instead. So something like this will work:

mygrep() { grep "$1" *.txt; }

Now when we run:

mygrep hello

It’ll give us the desired expansion. So despite functions not strictly belonging to the “alias” keyword, the utility is similar, so everyone using aliases should be aware of how powerful functions can be in this regard.

Conclusion

As you can see, a bash alias can be extremely useful for all kinds of scenarios involving Linux administrators. Hopefully, you can use some of the ideas I’ve presented to craft your own, unique aliases that will save you time.

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

How to Use the Tee Command in Linux

The tee command in Linux is useful when you want to direct the output of a command to multiple locations. Here's how to use it.

Using the “whois” Command – All you Need to Know

If you want to know about who owns a domain, or when it expires, then you need to use the "whois" command. Here's all you need to know.

Curl vs Wget: Choosing the Right Tool for the Job

Linux has two popular tools for getting data from third party websites. Here's the difference between curl and wget.

How to Tar and Gzip a Folder

Here's how to archive and compress a folder so that it's easy to move it from one location to another - In both Linux AND Windows!

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA