"alias" command in Linux
The alias command is one of many commands referred to as Bash Built-In commands, meaning it is inherent to the bash shell and does not rely on an external program. Alias is used in many ways, but perhaps its most frequent use is that of shortening the number of keystrokes required at the command line to perform a given task.
Lets look at the following example, a simple directory listing, consisting of the ls command, followed by a number of options to the command.
# ls -lvh
This outputs the directory listing to your screen, such as:
# ls -lvh total 2.1G -rw-r--r--. 1 root root 0 Feb 7 13:27 file01 -rw-r--r--. 1 root root 2.9M Sep 22 2016 links-2.13-1.el7.x86_64.rpm -rw-r--r--. 1 root root 2.0G Jan 7 2015 swap
Nothing new there, however with alias we can shorten the number of keystrokes needed to accomplish this task very easily, simply enter something similar to the following:
# alias lvh='ls -lvh'
Now type the following command:
# lvh total 2.1G -rw-r--r--. 1 root root 0 Feb 7 13:27 file01 -rw-r--r--. 1 root root 2.9M Sep 22 2016 links-2.13-1.el7.x86_64.rpm -rw-r--r--. 1 root root 2.0G Jan 7 2015 swap
As you can see the output of the command is the same as before, it just took fewer keystrokes to get there. Alias takes the command string of ls -lvh and makes it accessible through the lvh alias. The alias name can be anything you want assuming there is not a command available which already uses the name you choose. Welcome to the beauty of the alias command. The aliases which have been defined are user-specific so keep that in mind, also, if you ever need to see what aliases exist for a given user, just issue the following command logged in as that user:
# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias lvh='ls -lvh' alias mv='mv -i' alias rm='rm -i' alias rvm-restart='rvm_reload_flag=1 source '\''/usr/local/rvm/scripts/rvm'\''' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'