Signup/Sign In

How to Create Alias of Command in Linux (alias command)

In Linux, if we want to create an alias of any, we use the alias command.

The meaning of alias is "By the way". In the Linux/Unix operating system when we are using large commands multiple times so prevent writing large commands multiple times we create an alias of those commands. The alias command creates a shortcut of another large command and provides the same functionality.

The general syntax of the alias command.

alias [-p] [name[=value] ... ]

Types of Aliases

There are two types of aliases -

  1. Temporary Aliases
  2. Permanent Aliases

Temporary Aliases - This type of alias is as long as our current shell is active once we log out and come back later, these aliases are no longer. We can create temporary aliases using the below syntax as follows

$ alias alias_name = 'Custom Command' 

Permanent Aliases - This type of alias is permanent. We can create permanent aliases by saving them in the user's shell configuration file.

Brief description of options available with the alias command.

Option Description
-p print all defined aliases in a reusable format
--help display help information and exit

Example: Create an alias for printing the content of a file.

In this example, we create an alias for printing the content of a file that is available in another directory.

Image is loading

Example: print all defined aliases in a reusable format.

In this example, we can print all defined aliases in a reusable format using -p option.

Example: Removing an existing alias.

To remove existing alias the unalias command is used.

Conclusion

In this tutorial, we covered how to create an alias of command and removing existing alias in the Linux operating system.



About the author:
Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.