Uses for Aliases

This section describes various ways you can put aliases to work, making it easier to issue commands.

Aliases Save Typing

One of the principal benefits of aliases is that they save typing. They can achieve this end in many different ways, as shown below:

  • To provide shorter names for commands:

    alias m more                        Map m to more
    alias j jobs                        Map j to jobs
  • To string commands together in a pipeline:

    alias wsm 'who | sort | more'       Define wsm as sorted, paged who command
    alias print 'pr \!* | lpr'          Print files
  • To execute a sequence of commands:

    alias cl 'cd \!* ; ls'              Change to directory, then list it
  • To construct commands that supply default arguments to other commands:

    alias askrm rm -i                   Define safer rm command
    alias gora gopher gopher.ora.com    Connect to gopher.ora.com
  • To move into commonly used directories:

    alias .. cd ..                      Move to parent directory
    alias mq cd /usr/spool/mqueue       Move to mail queue directory

Aliases Can Redefine Commands

An alias name can be the same as the command invoked by the alias definition. This is a special case that's not a loop. Instead, it effectively changes the normal meaning of the command. For instance, if you usually do case-insensitive searches when you use grep, you can alias grep to supply the -i argument by default:

alias grep grep -i

To use the command name with its original meaning, precede it with a backslash, or invoke the command using its full pathname:

% \grep hognose *.ms
% /bin/grep hognose *.ms

It's not a good idea to redefine the meaning of dangerous commands, ...

Get Using csh & tcsh now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.