pavement

Alias (command)

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
 
m (Reverted edits by DavidYoung (talk) to last revision by 173.165.130.129)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
The [[alias]] command is used to create [[aliases]].
+
The [[alias]] command is used to create '''aliases''', and to get a list of aliased commands.
  
The syntax if shell dependant :
+
==Aliases creation==
  
'''B-Shell''' ([[sh]], [[bash]]) :
+
The syntax is shell dependent:
 +
 
 +
'''B-Shell''' ([[sh]], [[bash]]) and '''Z-Shell''' ([[zsh]]) :
 
  alias l=ls
 
  alias l=ls
 
  alias la='ls -A'
 
  alias la='ls -A'
Line 11: Line 13:
 
  alias la 'ls -A'
 
  alias la 'ls -A'
  
See also: [[unalias]]
+
==Special functions==
 +
 
 +
Some shells provide additional features, such as the '''-g''' argument of [[zsh]]'s alias [[built-in]] command. This allow creation of ''global aliases'' :
 +
'''> alias a=aaa'''
 +
'''> alias -g b=bbb'''
 +
'''> echo a b'''
 +
a bbb
 +
This can be very useful :
 +
'''> alias -g ...='../..''''
 +
'''> pwd'''
 +
/foo/bar/misc
 +
'''> cd ...'''
 +
'''> pwd'''
 +
/foo
 +
 
 +
For more information on the specific options of your shell, check its man page.
 +
 
 +
==Aliases consultation==
 +
 
 +
You can use this to get a list of existing '''aliases''':
 +
'''> alias'''
 +
...=../..
 +
....=../../..
 +
.....=../../../..
 +
......=../../../../..
 +
.......=../../../../../..
 +
clean='rm -f `find . -name "*~" -o -name ".*~" -o -name ".*.core" -o -name "*.core" -o -name "#*#" -o -name "a.out"`
 +
close='cdcontrol -f /dev/cd0 close'
 +
eject='cdcontrol -f /dev/cd0 eject'
 +
fr='export LANG=fr_FR.ISO8859-15'
 +
la='ls -a'
 +
ll='ls -Al'
 +
ls='ls -FG'
 +
'''> alias ls'''
 +
ls='ls -FG'
 +
 
 +
See also: [[unalias]], [[which]]
  
 
[[Category : System Commands]]
 
[[Category : System Commands]]

Latest revision as of 16:27, 25 August 2012

The alias command is used to create aliases, and to get a list of aliased commands.

[edit] Aliases creation

The syntax is shell dependent:

B-Shell (sh, bash) and Z-Shell (zsh) :

alias l=ls
alias la='ls -A'

C-Shell (csh, tcsh) :

alias l ls
alias la 'ls -A'

[edit] Special functions

Some shells provide additional features, such as the -g argument of zsh's alias built-in command. This allow creation of global aliases :

> alias a=aaa
> alias -g b=bbb
> echo a b
a bbb

This can be very useful :

> alias -g ...='../..'
> pwd
/foo/bar/misc
> cd ...
> pwd
/foo

For more information on the specific options of your shell, check its man page.

[edit] Aliases consultation

You can use this to get a list of existing aliases:

> alias
...=../..
....=../../..
.....=../../../..
......=../../../../..
.......=../../../../../..
clean='rm -f `find . -name "*~" -o -name ".*~" -o -name ".*.core" -o -name "*.core" -o -name "#*#" -o -name "a.out"`
close='cdcontrol -f /dev/cd0 close'
eject='cdcontrol -f /dev/cd0 eject'
fr='export LANG=fr_FR.ISO8859-15'
la='ls -a'
ll='ls -Al'
ls='ls -FG'
> alias ls
ls='ls -FG'

See also: unalias, which

Personal tools