Previous Table of Contents Next


Module 104
popd (csh)

DESCRIPTION

The internal csh popd command removes the top directory from the directory stack, then changes directory to the new top directory. The directory stack is created using the pushd command. Each time you use pushd the given directory argument is pushed onto the directory stack. The top directory is position zero with increasing numbers for other directories in the stack.

When you popd, the top directory is removed from the stack and the csh performs a cd stack[0], where stack sub zero is the top directory in the stack.

The stack maintains the last entry on the stack. If you try to pop the only entry left on the stack, the popd command complains the stack is empty.


NOTE:  
The ksh implements popd with functions. Check with your system administrator to see if popd is available.



COMMAND FORMAT

The format of the popd command follows.

     popd [ +n ]

Options

The following list describes the options and their arguments that may be used to control how popd functions.

+n If a plus precedes a number n then the nth entry in the stack is removed. Remember entries are numbered starting at zero.
If no option is provided, the top directory (entry zero) is removed from the directory stack and the new top entry becomes the current working directory.

TIP:  Most users of the csh alias the pushd, popd, and dirs commands. For example, you might want to add the following lines to your .cshrc file.


     alias u pushd  # use u instead of pushd
     alias o popd   # use o instead of popd
     alias d dirs   # use d instead of dirs

DIAGNOSTICS AND BUGS

If the stack is empty you are notified. If you specify a number greater than the number of stack entries you are notified.

RELATED COMMANDS

Refer to the dirs and pushd command described in modules 36 and 110.

APPLICATIONS

The popd command used in conjunction with the pushd and dirs command provides a method of changing directories quickly. You no longer have to type an entire directory path twice. Once you pushd to a directory, you can use popd to return to the directory.

TYPICAL OPERATION

In this activity you use the popd command to remove the top directory from the directory stack. Begin at the shell prompt.

1.  Type dirs and press Return to list the current directory stack.
     cj> dirs
     ~ ~ /usr/spool/uucppublic /usr/lib
2.  Type popd and press Return. The top directory is removed from the stack and the shell changes to the new top directory.
3.  Turn to Module 36 to continue the learning sequence.


Previous Table of Contents Next