Skip to content

Create and Use Alias Command in Linux

In this tutorial, you will learn how to create and use custom alias commands in Linux.

You can see a list of defined aliases on your profile by simply executing the alias command.

$ alias

Linux Alias Syntax

The alias command uses the following syntax:

alias [option] [name]='[value]'

The different elements of the alias command syntax are:

  • alias: Invokes the alias command.
  • [option]: Allows the command to list all current aliases.
  • [name]: Defines the new shortcut that references a command. A name is a user-defined string, excluding special characters and ‘alias’ and ‘unalias’, which cannot be used as names.
  • [value]: Specifies the command the alias references. Commands can also include options, arguments, and variables. A value can also be a path to a script you want to execute.

Create a Linux alias

Creating a Linux alias is very easy. You can create two types of aliases, i.e temporary and permanent. You can create temporary alias by entering them at the command line as you’re working, or you can put them in one of your startup files, like your .bash_profile or .bashrc or .zshrc or .bash_aliases files to create permanent alias, so they will be available every time you log in.

Open the .bashrc file,  close to the end of the file, there is a section with a couple of aliases (llla, and l). Let’s add the following lines to that part of the .bashrc file

alias proc="ps auwwx"
alias pfilter="ps auwwx | grep "
alias start="systemctl start "
alias stop="systemctl stop "
alias ena="systemctl enable "

This code will introduce five new aliases:

  • To see a list of processes
  • To filter processes according to the keyword to be typed in after pfilter
  • To start the service; service name to be typed after start (Ex: start nginx)
  • To stop the service; service name to be typed after stop (Ex: stop nginx)
  • To enable the service; service name to be typed after ena (Ex: ena crond)

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments