alias
alias is a built-in Linux command that defines shortcuts to longer (sets of) commands. The alias name is in fact a link to another command or command sequence. The Bash shell system wide aliases are set in /etc/bashrc, while users can define their own in ~/.bashrc.
[code lang=”bash”]
$ cat ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
alias update=”sudo yum update”
[/code]
The above update alias will execute ‘sudo yum update’ each time it is run from a terminal. In a similar manner, more complex aliases can be defined.
[code lang=”bash”]
alias my_script=’if [ $HOSTNAME=”localhost.localdomain” ]; then echo “hostname is not defined”; else echo “hostname is defined”; fi’
[/code]
Each time my_script is executed, it checks for the machine’s hostname and warns if the output is the default localhost.localdomain.
Running ‘alias‘ displays the current aliases for the user’s session.
[code lang=”bash”]
$ alias
alias l.=’ls -d .* –color=auto’
alias ll=’ls -l –color=auto’
alias ls=’ls –color=auto’
alias mc=’. /usr/libexec/mc/mc-wrapper.sh’
alias my_script=’if [ $HOSTNAME=”localhost.localdomain” ]; then echo “hostname is not defined”; else echo “hostname is defined”; fi’
alias update=’sudo yum update’
alias vi=’vim’
alias which=’alias | /usr/bin/which –tty-only –read-alias –show-dot –show-tilde’
[/code]
An alias can be unset using the unalias command.
[code lang=”bash”]
unalias my_script
[/code]