5 Most Used alias Commands in Linux With Examples

This tutorial will show you the five most used alias commands in Linux with examples.

Sometimes we need to reference some command using it with a shortcut. These commands with shortcuts defined in Linux are called <b<aliases. Aliases are used to replace long commands in order for the user to avoid spelling errors. Some administrators or regular users are using aliases because they are used to executing some commands with their own Linux language words that have been used over the years.

In this tutorial, we are going to use the latest Ubuntu 22.04 distribution. You can choose any Linux distro you want. Let’s get started!

Prerequisites

  • A server with Ubuntu 22.04 OS
  • User privileges: root or non-root user with sudo privileges

Update the System

Every fresh installation of Ubuntu 22.04 requires the system packages to be updated to the latest versions available.

sudo apt update -y && sudo apt upgrade -y

Once the system is updated, we are ready to show you the 5 most used alias commands in Linux.

Alias location and syntax

before we start with alias commands, it is important to be explained where the aliases are stored in our system and how they are defined. Well, the alias commands are stored in .bashrc file on our server. The syntax is the following:

alias NameOfAlias='TheOriginalCommand'

The syntax starts with the alias command, then with the name of the alias we want to use, then the equal = sign, and last is the original Linux command in quotation marks.

Once we define our alias in the .bashrc file on our server, we need to save the changes with our favorite editor and execute the following command in the terminal in order for the latest alias to be registered on the system.

source .bashrc

1. The ll alias

The ll alias is used for listing the files and folders on our system. Instead of using every time the ls -alF command, we can simply use this alias, and we will get the output in no time.

alias ll='ls -alF'

2. The search alias

Sometimes when we are trying to find some specific output by some word, we are using the grep command, for example:

ll | grep active

We list the files or folders with the “active” words in their names. The grep command should filter them but is more intuitive if we use the search word. That is why we are going to define this alias.

alias search='grep'

3. The Update and Upgrade alias

We often use the commands to update and upgrade the packages to the latest available versions. We use these commands:

apt-get update -y && apt-get upgrade -y

We can simply create an alias like this to save time with this command.

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

4. The count alias

Administrators and regular Linux users often want to count the number of files in a specific directory. For that purpose, they need to find the files and use the pipe with the wc -l command:

find . -type f | wc -l

We can simply create an alias count that will return the same output as the command above:

alias count='find . -type f | wc -l'

5. The ports alias

This alias is used when we need information about network connections, protocols, IP addresses, and ports that services are running on. The original command is netstat -tunlp. Since it can be simplified with an alias, we can easily create it:

alias ports='netstat -tunlp'

These were the five most used aliases in the world of Linux system administrators. There are plenty of useful long commands that are used on a daily basis and can be simplified with aliases. In this tutorial, you learned the syntax on how to create aliases and save them into the .bashrc file.

If you liked this post about the five most used alias commands in Linux with examples, please share it with your friends on social networks or simply leave a reply below. Thanks.

Leave a Comment