Creating a command alias (alias shell command)

An alias lets you create a shortcut name for a command, file name, or any shell text. By using aliases, you save a lot of time when doing tasks you do frequently. You can create a command alias.

Use the alias Korn shell built-in command to define a word as an alias for some command. You can use aliases to redefine built-in commands but not to redefine reserved words.

The first character of an alias name can be any printable character except the metacharacters. Any remaining characters must be the same as for a valid file name.

The format for creating an alias is as follows:
alias Name=String
in which the Name parameter specifies the name of the alias, and the String parameter specifies a string of characters. If String contains blank spaces, enclose it in quotation marks.
The following are examples how to create an alias:
  • To create an alias for the command rm -i (prompts you before deleting files), at the prompt, type the following:
    alias rm="/usr/bin/rm -i"
    In this example, whenever you enter the command rm, the actual command performed is /usr/bin/rm -i.
  • To create an alias named dir for the command ls -alF | pg (which displays detailed information of all the files in the current directory, including the invisible files; marks executable files with an * and directories with a /; and scrolls per screen), at the prompt, type the following:
    alias dir="/usr/bin/ls -alF | pg"
    In this example, whenever you enter the command dir, the actual command performed is /usr/bin/ls -alF | pg.
  • To display all the aliases you have, at the prompt, type the following:
    alias
    The system displays information similar to the following:
    rm="/usr/bin/rm -i"
    dir="/usr/bin/ls -alF | pg"