tcsh Aliases


tcsh lets you set command aliases.

You can use aliases to:


  • Set an alias or print what an alias is set to:
    % alias [-p] [name[=value] ...]
  • Remove an alias:
    % unalias [-a] [name ...]

Configure Short Forms of Frequently-Used Commands

  • A common example is aliasing h to history:
    % h
    h: Command not found
    % alias h history
    % h
         1  21:37   h
         2  21:37   alias h history
         3  21:37   h

Call Commands with Desired Flags by Default

  • Berkeley version of ls has two flags I like so I have ls aliased to ls -AF
    % alias ls '/usr/ucb/ls -AF'
    % ls
    .Xauthority       .login*           .twmrc            .xsession@
    .Xdefaults        .newsrc           .xinitrc*         .xsession-errors
    .cshrc            .sh_history       .xmotd            mbox
    % alias ls
    /usr/ucb/ls -AF
    % unalias ls
    % ls
  • You need to be a little careful with aliases.
  • Some people alias rm to be rm -i, which asks for confirmation before removing files.
  • If you get a new account and forget to add that alias, you could accidentally remove files.

Correct Typical Spelling Errors

  • People who frequently mistype mroe when they actually mean more might set:
    % alias mroe more

Set Up Commands that Work on Other Systems

  • People more familiar with Microsoft Windows commands than UNIX commands might alias dir to run ls.
  • If you will be using UNIX regularly, it is usually best to not add too many other system command aliases and just learn the real UNIX commands.


  • Aliases only get expanded for things in the command portion of the command line.
  • alias commands themselves go in .cshrc.
  • If you want command line arguments to appear inside an alias, you need to use history-like mechanisms to get them there.
  • For example, if you wanted to set up an alias that would start up the editor for you appending .txt to the name of the filename you give on command line you could use
    % alias vitxt 'vi \!$.txt'
  • Quotes are needed around string and the backslash before "!" is necessary so that shell doesn't use it for history substitution before it uses it to indicate arguments being inserted into an alias.
  • You can use \!*to indicate all command line arguments should be added to alias instead of just the last one:
    % alias edit 'vi \!*'
    % edit prog.c
  • If alias does not contain history substitutions, then original command line arguments will not change after the alias is expanded.
  • If alias does contain history substitutions, then alias will become new command and history substitutions will be done as if the line you typed with the alias on it was the previous command.
  • Alias substitution loops until the first word of the resulting line has no alias in it.
  • Shell does notice if an alias doesn't change the first word, as well as other possible loops so that "alias ls 'ls -AF'" is valid.
  • There are a few special aliases that are not set by default but if you set them to something they get run at certain times.
    • beepcmd gets run when the shell wants to send a beep.
    • cwdcmd runs after every change of working directory (cd command).
    • periodic runs periodically, you set period in seconds with shell variable tperiod.
    • precmd runs just before you get a command prompt.
  • For example, most often the first thing you do after using cd to change directories is do ls to see what is there so can make that the cwdcmd alias:
    % ls Mail
    mail.apr  mail.feb  mail.jan  mail.mar  mail.may
    % cd Mail
    mail.apr  mail.feb  mail.jan  mail.mar  mail.may
    % cd ..
    .Xauthority       .newsrc           .xmotd            mbox
    .Xdefaults        .sh_history       .xsession@
    .cshrc            .twmrc            .xsession-errors
    .login*           .xinitrc*         Mail/