alias Command

Purpose

Defines or displays aliases.

Syntax

alias [ -t ] [ -x ] [ AliasName [ =String ] ] ...

Description

The alias command creates or redefines alias definitions or writes existing alias definitions to standard output.

If no flags or parameters are supplied, all existing alias definitions are written to standard output. You can display a specific alias definition by using the AliasName parameter.

Create a new alias by using the AliasName=String parameter pair. When the shell encounters an alias on the command line or in a shell script, it substitutes the definition supplied by the string. The String variable can contain any valid shell text. Enclose the value of the String variable in single quotes if the string contains spaces. If the AliasName parameter is not a valid name, the alias command displays an error message.

If you specify the -t flag, the shell displays aliases that are tracked. A tracked command uses the full path name of the command. A tracked command can become undefined when the value of the PATH environment variable is reset, but aliases created with the -t flag remain tracked.

If you specify the -x flag, the shell displays aliases that are exported. An exported alias is active in all shells.

An alias definition affects the current shell environment and the execution environments of any subshells. The alias definition affects neither the parent process of the current shell nor any utility environment invoked by the shell.

Flags

Item Description
-t Sets or displays all existing tracked aliases. If this flag is used with the AliasName parameter, the new alias is tracked and the alias definition includes the full path name obtained by doing a path search. When the value of the PATH environment variable is reset, the alias definition becomes undefined but remains tracked.
-x Displays all existing exported alias definitions. If this flag is used with the AliasName parameter, the new alias is exported. Exported alias are not defined across separate invocations of the shell. You must put alias definitions in your environment file to have aliases defined for separate shell invocations.

Exit Status

The following exit values are returned:

Item Description
0 Successful completion.
>0 One of the specified alias name did not have an alias definition, or an error occurred.

Examples

  1. To change the ls command so that it displays information in columns and annotates the output, enter:
    alias ls='ls -CF'
  2. To create a command for repeating previous entries in the command history file, enter:
    alias r='fc -s'
  3. To use 1KB units for the du command, enter:
    alias du=du\ -k
  4. To create a command to display all active processes for user Dee, enter:
    alias psc='ps -ef | grep Dee'
  5. To see the full path name of the ls command, enter:
    alias -t ls
    The screen displays ls=/usr/bin/ls.

Files

Item Description
/usr/bin/ksh Contains the Korn shell alias built-in command.
/usr/bin/alias Contains the alias command.