How to Create Aliases and Shell Functions on Linux

Share
  • September 20, 2019

Fatmawati Achmad Zaenuri/Shutterstock.com

Create your own Linux commands using aliases and Bash shell functions. Tame repetitive tasks, truncate long-winded processes, and configure standard commands with the options you always use and struggle to remember.

Aliases and shell scripts are powerful techniques in Linux and Unix-like operating systems that allow you to hone your command line experience to be just what you want. You can define your own commands suited to your specific needs, and to ease the burden of repetitive tasks.

Aliases and shell scripts do the same sort of job. They allow you to define—and name—a set of Bash shell functionality that is then callable by the name you’ve given to it. Typing the name is easier and more convenient than having to type out all of the steps or commands each time you want to use them.

The difference between an alias and a script is one of complexity and scale. Scripts are better at holding longer and more elaborate chunks of code. Aliases are perfect for holding shorter, more succinct, sets of commands.

Predefined Aliases

Some aliases are predefined for you. To see the list of aliases that are defined in your system, use the alias command with no parameters:

alias

alias in a terminal window

These are the aliases that are defined on the Ubuntu test machine this article was researched on. If I’d defined any custom aliases, these would show up in this list too.

At the top of the listing, there’s a complicated-looking alias called alert. We’ll come to that in a moment. There’s a bunch of different aliases for the ls command, and there’s a group of aliases that provide color output to the grep family of commands. For example, with these aliases defined, whenever you type:

grep

The system will interpret it as:

grep --color=auto

Read the remaining 90 paragraphs

Source : How to Create Aliases and Shell Functions on Linux