Create aliases

The alias command is used in Linux to create a shortcut (alias) to any command and options. Aliases are usually used to assign easier-to-remember names to some commands, to implement desirable command options as the default for commands or to create a shortened version of a command to minimize the amount of typing.

You can add and list aliases using the alias command. The syntax is:

alias NAME=’command’

For example, if you are coming from the Windows world, you might be used to type dir to display the list of files and directories in the current directory. You can create an alias named dir that will execute the ls -l command:

linux alias command

You can define an alias that executes more than one command:

linux alias more commands

In the example above you can see that dir executes the ls -l and pwd commands.

You can also use the alias command to change the default behavior of the existing commands. For example, if you want the ls command to always display a file list using the long listing format, you can specify an alias that will execute the -l option by default:

linux alias ls

To print the current values, type alias without any options:

linux print aliases

To remove an alias, type unalias NAME:

linux unalias command

Subscribe to our Newsletter

Like us on Facebook

top
Geek University 2019