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 % ...

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.