Linux tip for DevOpsđź’ˇ: what is Alias and how will it save you time?

Andrey Byhalenko
DevOps Manuals and Technical Notes
3 min readJan 20, 2024

In this article, I will explain what an alias is in Linux and why you should use it.

Photo by Gabriel Heinzer on Unsplash

In this example, I have 12 files in my home directory:

Each file is structured in the same way: <name>_report-<count>.doc

What if I want to count reports by my name?

I can use the following command:

ls | grep andrey | wc -l

I got the result, but the command is pretty long to type every time I need it.
So I can create an alias and use it.
The alias command creates a shortcut to the original command (creates a link between the shortcut and the original command).
That means that the original command will be available as well; it’s only the link.

alias myf='ls | grep andrey | wc -l'

So as you can see, the myf command is counting my files now,
as well as ls | grep andrey | wc -l.
Now it’s much faster and easier.

Once you don’t need the alias anymore, you can remove it.

unalias myf

Note that alias will be removed when you log out.
In order to make it permanent, you need to append the alias in the ~/.bashrc file ($HOME/.bashrc) file executed by bash for non-login shells.

  • Edit the ~/.bashrc file:
vim ~/.bashrc
  • Append your bash alias.
  • Save and close the ~/.bashrc file.
  • Activate alias:
source ~/.bashrc

Of course, in the real world, you probably will not use the Linux command line to count the files or whatever; you will probably use some automation tool for that to display the report of all files or whatever you need.

But it’s important to understand how aliases work in Linux.

By the way, there are “build-in” aliases in every Linux distribution; you can list them by executing the alias command in the terminal:

If you liked my articles, join my newsletter, and you will receive weekly DevOps tutorials, articles, and tips every Saturday.

As a bonus, you will receive a free step-by-step DevOps CI/CD project, which you can use in your portfolio.

Subscribe here: https://junior-devops-hub.ck.page

--

--

Andrey Byhalenko
DevOps Manuals and Technical Notes

I'm a DevOps Engineer, Photography Enthusiast, and Traveler. I write articles aimed at junior DevOps engineers and those aspiring to become DevOps engineers.