Alias command in Linux (keyboard shortcuts)
An important feature of the shell is the possibility of creating nicknames or Linux shortcuts for commands. It can be used to simplify commands with many options or execute several processes in sequence. The alias command creates these shortcuts:
$ alias nickname=“commands”
In this example, the nickname psweb corresponds to the ps -e | grep nginx commands:
The list of nicknames can be displayed with the alias command without any parameters:
alias l=‘ls -AlF’
alias la=‘ls -la’
alias ll=‘ls -l’
alias ls=‘/bin/ls $LS_OPTIONS’
alias psweb=“ps -e |grep nginx” Some distributions make use of some pre-configured nicknames to facilitate the “transition” of users who are used to the Windows prompt. Others include options in commands such as rm and mv, to avoid overwriting files without asking:
An interesting alias for verifying the size of a directory and its subdirectories can be done with:
Another very “lazy” alias is to open a tar file:
If you want a little strength to create an 8-character password:
You can also mimic the Windows ping with just 5 pongs:
If you need a web server in any directory to do some quick tests:
Do you want to know your external IP (valid on the Internet) directly in the shell?
Several commands can be executed with the alias at once, using the semicolon ”;” to separate them:
In this example, the w, free, and df commands are executed with the nickname “verify “:
/dev/xvda1 16G 11G 5.3G 68%/
tmpfs 99M 0 99M 0% /run/user/1000 It is important to note that a nickname created in the shell will only exist permanently if it is saved in a Bash load script or in the profile configuration files. If you don’t save your aliases, when you log out, you’ll lose your keyboard shortcuts.
It is suggested to make the shortcuts permanent, save them to the .bashrc file in the user’s HOME directory.
Conclusion
If you use the shell a lot, you need to create your own list of shortcuts with the alias command to gain productivity. Just don’t get dependent… :-D
Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.