Aliases

One can define an alias for a command that is used often (and might be more complicated to type).
We will describe how to do it by considering an example.

NOTE: what is said below is correct for the csh and tcsh shells. For others some of the details and files could be different.

  • As an example, assume we want to remove the various auxiliary files produced by TeX or LaTeX. The name of these files end in .dvi, .aux, .log, etc. Thus, we can do
    rm *.dvi *.aux *.log
  • Since this is somewhat cumbersome, we could define an "abbreviation" for it:
    alias clean 'rm *.dvi *.aux *.log'
    respectively, for the bash shell
    alias clean='rm *.dvi *.aux *.log'
    Next time we can type clean to invoke the same command.

  • If we want to check what the meaning of clean is, we can use
    alias clean
  • To remove this alias, do
    unalias clean
  • To see all the aliases that are defined, use
    alias

    There are two inconveniences with this approach:

    To have a permanent alias, we should put it in a file devoted to this purpose. For the csh shell, this file is ~/.cshrc. For the tcsh shell, this file is ~/.tcshrc, or ~/.cshrc provided ~/.tcshrc does not exist (see the man page of tcsh, "Startup and shutdown" for more details).
    For the bash shell, the file is ~/.bashrc.

    This file is read once at the start of each shell.
    Hence, changes made after the shell is running are ignored. However, you can source the corresponding file to have the changes take effect.

    WARNING: These files contain important information for the shell. Be sure you do not alter that part!

    This is a sample ~/.cshrc (or ~/.tcshrc), containing the alias clean as well.
    The file has to end with a RETURN character.
    Comment lines begin with #.

    .... some other stuff
    
    # Aliases 
    
    alias cp	'cp -i'
    alias rm	'rm -i'
    alias mv	'mv -i'
    alias clean     'rm -i *.dvi *.log *.aux *.toc'
    
    (The meaning of -i in these commands is to ask for confirmation before deleting or overwriting a file.)

    A few technical details: