# Alias (command)

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Alias_(command)
> Markdown URL: https://mediated.wiki/source/Alias_(command).md
> Source: https://en.wikipedia.org/wiki/Alias_(command)
> Source revision: 1336333541
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Shell command that defines a word that acts like a command

For the aliasing of variables in a programming language, see [Aliasing (computing)](/source/Aliasing_(computing)).

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Alias" command – news · newspapers · books · scholar · JSTOR (July 2013) (Learn how and when to remove this message)

alias Example of alias command Original author Bill Joy Developers Various open-source and commercial developers Operating system Unix, Unix-like, AmigaDOS, FreeDOS, Microsoft Windows, ReactOS, AROS, KolibriOS, IBM i Platform Cross-platform Type Command

**alias** is a [shell](/source/Shell_(computing)) [command](/source/Command_(computing)) that defines a word that the shell replaces with associated text before interpreting a command line.[1] It is often used to enhance productivity by abbreviating a command or for including commonly used arguments with a command. The command is available in [Unix shells](/source/Unix_shell), [AmigaDOS](/source/AmigaDOS), [4DOS](/source/4DOS)/[4NT](/source/4NT_(shell)), [FreeDOS](/source/FreeDOS), [KolibriOS](/source/KolibriOS), [PowerShell](/source/PowerShell), [ReactOS](/source/ReactOS), [EFI shell](/source/Unified_Extensible_Firmware_Interface),[2] and [IBM i](/source/IBM_i).[3] Aliasing functionality in [MS-DOS](/source/MS-DOS) and [Command Prompt](/source/Command_Prompt) is provided by the [DOSKEY](/source/DOSKEY) command.

Since aliases are defined only for a shell session, regularly used aliases are often defined in a session startup [shell script](/source/Shell_script) such as .bashrc. The alias commands may either be written in the config script directly or [sourced](/source/Source_(command)) from a separate file.

Aliases were introduced in the [C shell](/source/C_shell) to survive in descendant shells such as [tcsh](/source/Tcsh) and [bash](/source/Bash_(Unix_shell)). As these aliases were limited to one line they were useful for creating relatively simple shortcut commands, but not more complex constructs. Older versions of the [Bourne shell](/source/Bourne_shell) did not offer aliases, but did provide functions, which are more powerful than the csh alias. Eventually, the csh alias was implemented in the [bash](/source/Bash_(Unix_shell)) and [ksh](/source/Korn_shell) shells. With shells that support both functions and aliases but no parameterized inline shell scripts, the use of functions wherever possible is recommended. Nonetheless, aliases are necessary where chained aliases are required.

## Features

### Define

The following is an example that defines gc to be a command the performs the action [git](/source/Git) commit.

alias gc='git commit'

In C shell and tcsh there is no equals sign:

alias gc "git commit"

To define an alias in PowerShell, the new-alias cmdlet is used:

new-alias ci copy-item

In PowerShell, an alias cannot be used to specify default arguments for a command. Instead, this must be done by adding items to the collection $PSDefaultParameterValues, one of the PowerShell preference variables.

In PowerShell, the set verb is used to change an existing alias. The following changes the alias ci to invoke the [cls](/source/Cls_(command)) command.

set-alias ci cls

In 4DOS/4NT shell, the eset command provides an interactive command line to edit an existing alias. For example:

eset /a cp

### List

To view defined aliases:

alias

To list aliases in a way that allows for re-creating them by sourcing the output (not available in 4DOS/4NT or PowerShell):

alias -p

To report the definition of a particular alias name:

alias myAlias

### Remove

In Unix shells and 4DOS/4NT, aliases can be removed via unalias. To remove the copy alias:

unalias copy

To remove all aliases (not available in 4DOS/4NT):

unalias -a

To remove all aliases in 4DOS/4NT:

unalias *

In PowerShell, an alias is removed from the alias:\ drive via remove-item:

remove-item alias:ci

### Ignore

In Unix shells, an aliased word can be used without replacement by using quotes. For example, consider the following command that defines an alias ls that invokes the original ls with options -la. To invoke the original ls command (without the options), the following syntax is used: 'ls' or \ls.

alias ls='ls -la'

In 4DOS/4NT shell, an asterisk is used. For example, the following defines dir to invoke the original dir (requires asterisk in the definition) with options /2/p. To later invoke the original dir, the syntax is *dir.

alias dir = *dir /2/p

### Chaining

Typically, aliases are used to replace the first word of a command line, but some shells such as bash and ksh also support chaining – replacing subsequent words.

For example, the following defines list to invoke ls and long to as a set of ls options. The command alias must end with a space to enable chaining.

alias list='ls '
alias long='-Flas'

Then, command line list long myfile expands to ls -Flas myfile.

The behavior provided by chaining is not possible via shell functions.

### Command arguments

In the [C Shell](/source/C_Shell), [arguments](/source/Argument_(computer_science)) can be embedded inside the command using the string \!*. For example, with this alias:

 alias ls-more 'ls \!* | more'

ls-more /etc /usr expands to ls /etc /usr | more to list the contents of the directories /etc and /usr, pausing after every screenful. Without \!*,

 alias ls-more 'ls | more'

would instead expand to ls | more /etc /usr which incorrectly attempts to open the directories in *more*.[4]

Some shells such as bash and ksh do not support this syntax, but do provide for similar functionality via shell functions — see [§ Alternatives](#Alternatives) below.

## Alternatives

Best practice is to only define an alias for a relatively simple command. Alternatives for more complicated logic include:

- A [shell script](/source/Shell_script), which provides a rich ability to implement a command

- A [symbolic link](/source/Symbolic_link) in the user's [PATH](/source/PATH_(variable)) (such as [/bin](/source/%2Fbin)), which in some cases may allow access to a buried command function for the small number of commands that use their invocation name to select the mode of operation

- A shell function, especially if the command being created needs to modify the internal [runtime environment](/source/Runtime_environment) of the shell (such as [environment variables](/source/Environment_variables)) needs to change the shell's [working directory](/source/Working_directory), or must be implemented in a way which guarantees that it appear in the command search path for anything but an interactive shell (especially any "safer" version of rm, cp, mv and so forth)

A relatively simple alias that includes a few arguments and supports subsequent arguments, can be converted to a shell function in a relatively straightforward process. For example, alias alias ll='ls -Flas' can be implemented as function ll () { ls -Flas "$@" ;}. To prevent a function from [calling itself](/source/Recursion), use [command](/source/Command_(Unix)): ls () { command ls --color=auto "$@" ; }. In older Bourne shells, use /bin/ls instead of command ls.

## References

1. **[^](#cite_ref-1)** Rugheimer, Hannes (2020-06-10). [*AmigaDOS quick reference : Rügheimer, Hannes : Free Download, Borrow, and Streaming : Internet Archive*](https://archive.org/details/1988-rugheimer-spanik-amigados-quick-reference). [ISBN](/source/ISBN_(identifier)) [9781557550491](https://en.wikipedia.org/wiki/Special:BookSources/9781557550491). Retrieved 2020-09-12 – via Internet Archive.

1. **[^](#cite_ref-EFI-Shells-and-Scripting_2-0)** ["EFI Shells and Scripting"](http://software.intel.com/en-us/articles/efi-shells-and-scripting/). [Intel](/source/Intel). [Archived](https://web.archive.org/web/20130927203229/http://software.intel.com/en-us/articles/efi-shells-and-scripting/) from the original on 2013-09-27. Retrieved 2013-09-25.

1. **[^](#cite_ref-3)** [IBM](/source/IBM). ["IBM System i Version 7.2 Programming Qshell"](https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc) (PDF). *[IBM](/source/IBM)*. [Archived](https://web.archive.org/web/20200918130823/https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc) (PDF) from the original on 2020-09-18. Retrieved 2020-09-05.

1. **[^](#cite_ref-4)** ["Examples of passing arguments given to a command alias"](https://web.archive.org/web/20121125074502/http://unixhelp.ed.ac.uk/shell/alias_csh2.1.html). *UNIXhelp*. [University of Edinburgh](/source/University_of_Edinburgh). Archived from [the original](http://unixhelp.ed.ac.uk/shell/alias_csh2.1.html) on 2012-11-25.

## Further reading

- McElhearn, Kirk (2006). *The Mac OS X Command Line: Unix Under the Hood*. [John Wiley & Sons](/source/John_Wiley_%26_Sons). [ISBN](/source/ISBN_(identifier)) [978-0470113851](https://en.wikipedia.org/wiki/Special:BookSources/978-0470113851).

## External links

The Wikibook *[Guide to Unix](https://en.wikibooks.org/wiki/Guide_to_Unix)* has a page on the topic of: ***[Commands](https://en.wikibooks.org/wiki/Guide_to_Unix/Commands)***

- [alias](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/alias.html): define or display aliases – Shell and Utilities Reference, [The Single UNIX Specification](/source/Single_Unix_Specification), Version 5 from [The Open Group](/source/The_Open_Group)

- [Bash man page for alias](https://www.ss64.com/bash/alias.html)

- [The alias Command](http://linfo.org/alias.html) by The Linux Information Project (LINFO)

v t e Unix command-line utilities and shell builtins File system cat chattr chmod chown chgrp cksum cmp cp dd du df file fuser ln ls mkdir mv pax pwd rm rmdir split tee touch type umask Processes at bg crontab fg kill nice ps time User environment env exit logname mesg talk tput uname who write Text processing awk basename comm csplit cut diff dirname ed ex fold head iconv join m4 more nl paste patch printf read sed sort strings tail tr troff uniq vi wc xargs Shell builtins alias cd echo test unset wait Searching find grep Documentation man Software development ar ctags lex make nm strip yacc Miscellaneous bc cal dc expr lp od sleep true and false Categories Standard Unix programs Unix SUS2008 utilities List

---
Adapted from the Wikipedia article [Alias (command)](https://en.wikipedia.org/wiki/Alias_(command)) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Alias_(command)?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
