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 is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command. Typically, an alias will last for the life of the shell session but regularly used aliases can 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) so that they will be available for all shell sessions.
Contents |
Aliases can be created by supplying name/value pairs as arguments for the alias command. An example of the bash shell syntax is:
alias copy="cp"
The corresponding syntax in the csh or tcsh shell is
alias copy "cp"
This alias means that when the command copy is read in the shell, it will be replaced with cp and that command will be executed instead.
To view defined aliases the following commands can be used:
alias # Used without arguments; displays a list of all current aliases alias -p # Analogous to the above alias copy # Displays the alias for copy
If an alias exists for a command, it is possible to override the alias by surrounding the command with quotes. For example, consider the following alias definition:
alias ls='ls -la'
To override this alias and execute the ls command as it was originally defined, the following syntax can be used:
'ls'
Aliases can be removed by executing the unalias command:
unalias copy # Removes the copy alias unalias -a # The -a switch will remove all aliases
Some commonly used aliases in the bash shell:
alias ls='ls --color=tty' # use colors alias la='ls -a' # list all files alias ll='ls -l' # long listing format alias rm='rm -i' # prompt before overwrite alias cp='cp -i' alias mv='mv -i' alias vi='vim' # use improved vi editor
When not using arguments, as in the vi alias defined above, one might create a symbolic link with the ln command rather than use an alias. This method will result in the vi command being available to all users, independent of the shell.
- : define or display aliases – Commands & Utilities Reference, The Single UNIX® Specification, Issue 6 from The Open Group
- Bash man page for alias
- The alias Command by The Linux Information Project (LINFO)
|
|
|
|---|---|
| File and file system management | alias · cat · chattr · cd · chmod · chown · chgrp · cksum · cmp · cp · du · df · file · fsck · fuser · ln · ls · lsattr · lsof · mkdir · mount · mv · pwd · rm · rmdir · split · touch |
| Process management | at · chroot · crontab · exit · kill · killall · nice · pgrep · pidof · pkill · ps · pstree · sleep · time · top · wait · watch |
| User management/environment | env · finger · id · logname · mesg · passwd · su · sudo · uname · uptime · w · wall · who · whoami · write |
| Text processing | awk · comm · cut · ed · ex · fmt · head · iconv · join · less · more · paste · sed · sort · tac · tail · tr · uniq · wc · xargs |
| Shell programming | basename · echo · expr · false · printf · test · true · unset |
| Printing: lp · Communications: inetd · netstat · ping · rlogin · nc · traceroute · Searching: find · grep · strings · Miscellaneous: banner · bc · cal · dd · man · size · yes | |