14.2 Korn Shell Features
14.2.1 Korn shell aliases
An alias is a way to give a command a different name for use in the shell. Aliases provide an excellent way to improve efficiency and productivity when using shell commands. When set from the command line, aliases are only activated for the shell in which they are created. Adding aliases to your .kshrc (covered in Chapter 15) file will activate them upon login or whenever a new window or shell is opened.
Command Format:
alias  aliasname=value

Figure summarizes the reasons to use aliases. Figure shows some examples creating aliases. Use single quotes for commands with options, spaces or other special characters. Note that there are no spaces between the alias command, the equal sign (=), and the command(s) being assigned to the alias.

  • Substitute a short command for a long one - You can reduce the number of keystrokes for commonly used long commands by creating an alias for the command. See Examples 1 and 2 in Figure
  • Create a single command for a series of commands - You can string several commands together and assign them one short alias name to reduce keystrokes. See Example 3 in Figure
  • Create alternate forms of existing commands - Some commands such as rm (remove files and directories) and cp (copy files) can be dangerous. If you are not careful, you could accidentally overwrite an important file. An alias will allow you to change the meaning of these commands to include the -i option so they prompt a user before overwriting a file or directory. See Example 4 in Figure

Displaying Aliases - To display aliases, use the alias command with no argument. Figure shows using the alias command to display all aliases set for the current session. Some aliases are pre-defined as part of the Korn shell.

Removing an Alias in the Current Shell - You can unset a previously defined alias with the
unalias command. Figure shows using the unalias command to unset the "bye" alias, which will no longer appear in the alias listing. You can also temporarily bypass an Alias. To bypass the alias and use the original version of a command, use a backslash.

Command Format:
unalias aliasname
Interactive Media Activity (Flash, 99 kB)
  Using Korn Shell Aliases

In this media activity, you are logged in as user2 and your current working directory is: /home/user2. Type the commands that would accomplish the requested objectives. 
Note: Be sure to press enter after each one. Click on step 1 to begin.