O'Reilly logo

Using csh & tcsh by Paul DuBois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working in Multiple Locations

Your work probably involves accessing information that's stored in more than one directory. For example, suppose you're working in directory A, and then change into directory B, to check something briefly before continuing your work in directory A. In other situations, you might move back and forth between directories on a more extended basis. Suppose you're working in ~/src/myprog to modify the source code for a program myprog, but occasionally need to review the contents of some of the system header files in /usr/include. One method of moving between directories is to supply a pathname each time you change directory:

% cd /usr/include
% cd ~/src/myprog
% cd /usr/include
% cd ~/src/myprog
% etc.

However, the method shown above is inefficient and tedious. You could visit and revisit a set of locations more easily if you could type a directory's name the first time you move into it, and then return to it later without having to type the name again. The following sections describe the shell's facilities for changing directories in this manner.

Using cd – To Return to the Previous Directory

In tcsh, the command cd – returns to your previous location, so successive cd – commands provide a convenient way to alternate between two directories. If you are currently in ~/src/myprog, you can alternate with /usr/include as shown below:

% cd /usr/include                Move to /usr/include
% cd -                           Return to ˜/src/myprog
% cd -                           Return to /usr/include
% cd -                           Return to ˜/src/myprog % ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required