Linux and Unix alias command

Quick links

About alias
Syntax
Examples
Related commands
Linux and Unix main page

About alias

alias instructs the shell to replace one string with another when executing commands.

Syntax

alias [name=['command']]

Description

Aliases are used to customize the shell session interface. Using alias, frequently-used commands can be invoked using a different, preferred term; and complex or commonly-used options can be used as the defaults for a given command.

Aliases persist for the current session. They can be loaded at login time by modifying the shell's .rc file. The invocation and usage of alias differs depending on the shell; see your shell's documentation for details.

Options

name Specifies the alias name.
command Specifies the command the name will be an alias for.
-a Removes all alias definitions from the environment of the current shell session.
-t Sets and lists tracked aliases.
-x Sets or prints exported aliases. An exported alias is defined for scripts invoked by name.

Examples

alias

Invoking alias with no arguments will display all currently aliased commands.

alias ls='ls --color=auto'

Creates the alias "ls" such that using the ls command will always display color output.

alias ll='ls -la'

Create an alias "ll" which will run ls with the options to display all files (-a) in a long list format (-l).

alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'

The above four commands create aliases for quickly navigating to one, two, three, or four higher-level directories, respectively. For instance, after these alises are set, typing the command "..." would navigate up the directory hierarchy three times.

alias port='netstat -tulanp'

Creates the alias "port", which would run netstat to display all currently open network ports.

Related commands

unalias