Command Aliases

The 'alias' command enables you to create another name for a command.

The alias doesn't replace the original command, though; it's simply a

synonym for it. You define an alias using the 'alias' command followed

by an equal sign and the command that the alias will stand for. For

example, the following command defines 'list' as an alias for 'ls':

$alias list=ls

You use this alias as you would use the original 'ls' command:

$list

mypog.c myprog.o

Command Options and Parameters

To include command options in an alias, enclose the command and its

option(s) in single quotes:

$alias sizes='ls -s'

The -s option lists files with their sizes in blocks. Therefore, the

alias 'sizes' displays the files in the current directory with their

sizes in blocks:

$sizes

mypog.c 6 myprog.o 12

You may include command parameters in an alias. The following alias

displays only files with the .c extension:

$alias listc='ls *.c'

$listc

mypog.c

You can use an exiting command name as an alias, too. In this case, the

alias hides the original command. Use this feature to hide dangerous

commands that might delete files inadvertently, change their names,

etc. Let's look at a concrete example. To ensure that 'mv' command

doesn't overwrite exiting files, define an alias called 'mv' that

overrides the 'mv -i' command (the -i option queries the user before

deleting existing files):

$alias mv='mv -i'

Listing and Canceling Existing Aliases

To list all the aliases in effect, use the 'alias' command without

additional parameters:

$alias

list = ls -s

sizes = ls -s

listc = ls *.c

rm = rm -i

To cancel an exiting alias, use the 'unalias' command followed by the

alias you wish to remove:

$unalias listc

What’s wrong? The new clean desk test
Join the discussion
Be the first to comment on this article. Our Commenting Policies