Unix Concepts   «Prev  Next»
Lesson 3 Managing aliases
Objective List current aliases and disable them.

List Current Aliases in Unix

Once a few aliases have been defined, you can manage them in different ways, as shown below:
CommandDescription
% aliasList currently defined aliases
% alias nameList the definition for the alias name
% alias | grep patternList all definitions that contain pattern
% \commandTemporarily disable the alias. Use the default command, not the alias by that name
% unalias nameDisable the alias definition for name for the rest of your UNIX session

These commands are demonstrated in the following ToolTip: Mouseover the image below to obtain more information.

Commands for Listing or Disabling Aliases in Unix

Unix alias command
Commands for listing or disabling alias
  1. alias command plus output: Without arguments, the alias command displays a list of defined aliases. The parentheses, (), indicate that the definitions are treated as a single argument.
  2. alias rm command plus output: With a single argument (the alias name rm), the alias command displays rm –i, the alias definition.
  3. rm qa.html plus prompt below: You want to remove the file qa.html. However, the rm command is really an alias for rm -i. As a result, the command prompts for confirmation.
  4. \rm qa.html command: To use the regular rm command, you need to disable the rm alias. This is done with the backslash (\). Now, the actual rm command is used, and the file is deleted without confirmation.
  5. alias|grep ls command: If you have many aliases, the grep command can help you find them. In this example, grep searches for aliases that contain the pattern ls.
  6. unalias ls: To disable an alias for the rest of your UNIX session, use the unalias command.
  7. alias | grep ls: Because you have disabled the ls alias, it no longer appears when you search for it.

The following section discusses additional information with respect to aliases.
Linux OS Concepts

Creating and Managing Unix Aliases

The user can create aliases in the Korn shell. An alias is a nickname for an existing command or commands. The real command(s) is substituted for the alias when the shell evaluates the command line.
1 $ alias cl='clear'
2 $ alias l='ls –laF'
3 $ alias ls='ls −aF'
4 $ \ls ..

Explanation:
  1. The alias cl is an alias for clear.
  2. The alias is l. The letter l is a nickname for the command ls –laF.
  3. The alias ls is assigned the command ls –aF.
  4. The backslash turns off the meaning of the alias for the execution of this line. The real ls command, not the alias, is executed.

Alias Commands
  1. alias: List all aliases
  2. alias rm: List a specific alias.
  3. alias rm rm -i: Define an alias.
  4. alias | grep rm: List all aliases that match a pattern.
  5. rm: Temporarily use the default command, not the alias by that name.
  6. unalias rm: Disable an alias for the rest of the session.

GNU/Linux Options
-7 Strip the eighth bit on input and output.
-b hostalias
Use bind(2) to bind the local socket to an aliased address or
the address of an interface other than the one that would be
chosen by connect(2).					

In the next lesson, the display of previous commands using the history feature will be discussed.

SEMrush Software 3 SEMrush Banner 3