Alias (Unix shell)
From Wikipedia, the free encyclopedia
In Unix shells (like csh, bash, etc.), alias is a command that enables a replacement of a word with another string. It's mainly used for abbreviating a system command, or for adding default arguments to a command which one regularly uses. For example:
alias xx="ls -l"
would enable one to type xx
to do ls -l
. This would last while the current shell was active and would not work in another shell or another session. Regularly used aliases could be placed in the shell's configuration file (~/.cshrc or the systemwide /etc/csh.cshrc for csh, or ~/.bashrc or the systemwide /etc/bashrc for bash) etc., to run them at login or shell startup.
For more permanent replacement that is independent of the shell, one might use a symbolic link rather than an alias:
ln -s /usr/bin/fullcommandname /usr/bin/shortercommand
Or without root access:
ln -s /usr/bin/somecommandlong ~/bin/shortcmd
Aliases cannot do more sophisticated stuff like taking arguments, etc. For that, most shells support functions instead.
Typical aliases (from bash):
alias ls='ls --color=tty' # use colors alias la='ls -a' alias ll='ls -l'
alias rm='rm -i' # prompt before overwrite alias cp='cp -i' alias mv='mv -i'
alias vi='vim' # use improved vi editor
[edit] Anonymous aliases
With anonymous aliases it's possible to use a command as it was meant originally defined, even if an alias with extra arguments exists for that command. For instance, if the following alias definition is set:
alias ls='ls -la'
We can still use "ls" as a no extra arguments command. In order to do so, just enter the command as follows:
'ls'