In this tutorial you will learn, how to create shortcut commands on Linux. This is you can say a short name of any command. In you daily work, you use multiple commands very frequently. You can create a shortcut of those commands, which help you to use easier.
Alias is an Linux command provides ability to create customized commands. Using this you can create a sort name for a big command as an alias, which is easier to remember. When we uses a single command very frequently, we can alias them to a very short name. You can understand it as create shortcut commands on Linux.
Create Shortcut Command
For example, we use below command frequently to view the directory listing in human readable format.
Now, make it short with alias command.
alias lh="ls -lh"
All done, You have created the alias successfully. To verify the newly created alias, just type below command on terminal
You will see the results on screen similar to command “ls -lh”.
Make Shortcut Permanent
When you create an alias on terminal, it is not available permanently. Once the terminal is closed, the aliase are lost. To make the aliases permanently you can write in login or non login shell script.
Add the aliases in /etc/profile.d/bash_aliases.sh (Use any name for this script) to make them available for all users. To configure aliases for specific user only, add them in ~/.bash_aliases file.
Create More Shortcut Commands
You can create multiple shortcut commands as much you need. Here is the aliases of some frequently used commands. Add these commands to shell script.
alias cd..='cd ..' alias ..='cd ..' alias ...='cd ../../../' alias reboot='sudo /sbin/reboot' alias poweroff='sudo /sbin/poweroff' alias apache2restart='sudo sytemctl restart apache2.service' alias apache2reload='sudo sytemctl reload apache2.service'
View all Shortcuts (Aliases)
You can simply type the “alias” command without any parameter to print all available aliases on your system.
You can use unalias command to disable any shortcut on your system. For example to disable ‘lh’ alias use following command.
You also need to remove any entry made in login or non login shell scripts.