Make the most out of Linux Shell Aliases

Photo by Lukas on Unsplash

Make the most out of Linux Shell Aliases

Aliases are a powerful and convenient way to reduce the time that you need to spend typing out long commands. It makes your life easier as a Linux user by essentially reducing lines of complex group of commands that are piped together down to a letter or a simple word.

For example, one of the most common commands for listing out all the files in the directory is ls -al. This command is almost used hundreds of times on a daily basis and lets try to reduce it to something small.

$ alias ls='ls -al`

image.png

As you can see from the above image, typing out just ls is giving out the actual output for ls -al. This is what aliasing is.

How to remove aliases

Suppose you did some mistake or you want to switch back to the way the original command was. You could make use of the unalias command or another way would be to close the current terminal.

$ unalias ls

How to make changes permanent

Now, as you might have noticed, once you close your current terminal, the aliasiing is not available anymore. In order to make the changes permanent, you can open up the .bashrc file and add the required line at the end.

vim .bashrc

Now add the following line to the end of the file

alias ls='ls -al'

As of now, the changes are permanent. Even if you open other terminal windows or close the current one, the aliases that you made will be available to you.

Summary

In this tutorial, we learned what is aliasing in Linux and how to make use of it. In fast paced work environments and typing boring long commands, aliases can be of great help.