<<

.

Define Aliases

Defining aliases allows you to create shortcuts for commands and their options or to create commands with entirely different names.

On a SUSE LINUX system, whenever you enter the commands , md, or , for instance, you use aliases.

You can find out about the aliases defined on your system by using the alias.

This will show you that dir, for instance, is an alias for ls -l and md is an alias for -p.

The following are examples of aliases that define new commands:

tux@da10:~> alias md alias md='mkdir -p' tux@da10:~> alias dir alias dir='ls -l'

To see whether a given command is an alias for something else, use the command.

For each command specified, type will tell you whether it is a

■ Built-in command

■ A regular command

■ A function

■ An alias

For regular commands, the output of type lists the to the corresponding executable. For aliases, it lists the elements aliased:

tux@da10:~> type -a ls ls is aliased to `/bin/ls $LS_OPTIONS' ls is /bin/ls

The above example shows that ls is an alias although, in this case, it is only used to add some options to the command.

The -a option is used to show both the contents of the alias and the path to the original ls command. The output shows that ls is always run with the options stored in the variable LS_OPTIONS.

These options cause ls to list different file types in different colors (among other things).

Most of the aliases used on a system-wide basis are defined in the file /etc/.bashrc.

Aliases are defined by using the alias command and can be removed by using the unalias command.

For example, entering

unalias ls

removes the alias for ls, causing ls to stop coloring its output.

The following is the syntax for defining aliases:

alias alias_name=’command options’ An alias defined in this way is only valid for the current shell and will not be inherited by subshells, as in the following:

tux@da1:~> alias =" Hello" tux@da1:~> ps Hello tux@da1:~> bash tux@da1:~> ps PID TTY CMD 858 pts/0 00:00:00 bash 895 pts/1 00:00:00 bash ...

.

To an alias persistent, you need to store the definition in one of the shell's configuration files.

On SLES 9, the file ~/.alias is intended for personal aliases defined by each user.

If it exists, this file is read in by ~/.bashrc, where a command is included to that effect.

Aliases are not relevant to shell scripts all, but can be a real time saver when using the shell interactively.

.