Using Aliases and Variables To Move Around

This section discusses how to use aliases to help you issue directory-changing commands more easily, and how to use variables to provide arguments for those commands.

Moving Around Using Aliases

One simple way to ease file system navigation is to create shorter command names using aliases:

alias pu pushd
alias po popd

Certain idiomatic forms of cd are also easily turned into aliases. Those shown below allow you to type .., /, or - to change into your parent directory, the root directory, or your previous directory:

alias .. cd ..
alias / cd /
alias - cd -                   (This one works only for tcsh)

If you visit certain locations frequently, aliases can make them easier to get to. A system administrator who often works in the mail queue directory or in /usr/adm might find these aliases useful:

alias mq cd /usr/spool/mqueue
alias adm cd /usr/adm

A programmer, on the other hand, would be more likely to use aliases like these:

alias ui cd /usr/include
alias uis cd /usr/include/sys
alias ul cd /usr/lib

Moving Around Using Variables

Commonly used directories can be accessed using variables rather than aliases. For example, to give yourself an alternate way of getting into /usr/include, set a variable in your ˜/.cshrc file, like this:

set ui = /usr/include

Then refer to the variable in directory-changing commands:

% cd $ui
% pushd $ui

Changing directory using an alias usually requires less typing than changing using variables, because you are typing one word (ui), instead ...

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.