Linux is a command line-based operating system even though it provides GUI. The bash provides the environment to run commands. Linux provides lots of commands some of them are hard to remember or hard to type. The Linux bash provides the
alias in order to shorten or rename commands. In this tutorial, we examine how to list, create and use an alias.
alias command is used to list existing and active alias via the command-line interface. Simply the alias command searched for bash configuration files and extracts the lines those starts with the
alias keyword. Apart from the alias command the alias keyword is used to define an alias in bash configuration files.
As we can see there are different aliases for different commands. The following example shows the
ls related alias which is named as
alias la='ls -A'
This alias can be called with the
la which actually calls the
ls -A command.
Create Temporary Alias
The alias keyword can be used to create alias in a temporary manner. The syntax of the alias keyword is like below.
alias ALIAS = "COMMAND"
- ALIAS is the new alias used to call COMMAND.
- COMMAND is the command which will be called with the ALIAS. The COMMAND can include parameters or options.
The alias command is not saved into bash configuration files and is lost after a reboot. In the following example, we create an alias with the name of
mycd in order to navigate to the
$ alias mycd = "cd /mnt"
Then we can call simply running
mycd like below.
Create Permanent Alias
Aliases created via the command-line interface using the alias keyword are not permanent and they are lost when the system is rebooted. In order to create permanent alias, the alias should be stored in the shell configuration files like below for different shell types.
- Bash ~/.bashrc
- Zsh ~/.zshrc
First, we open the bash configuration file with our favorite text editors like vim or nano.
$ vim ~/.bashrc
Then add the following line and save the file.
alias mycd = "cd /mnt"
Existing alias can be removed by using the
unalias command. The unalias command syntax is like below.
In the following example, we remove the alias named