The Directory Stack

The Directory Stack

The directory stack is a list of directories that you can use to save yourself some typing as you navigate around the directory tree. In traditional Last In First Out (LIFO) data structures, you must retrieve data (in this case, directories) in reverse of the order in which they were stored. That is also true by default in accessing the directory stack. However, unlike classical LIFO stacks, the tcsh directory stack provides a mechanism (an option to popd) for accessing the directories out of sequence.

Example: Say you're in the directory dir1. You want to move around a little bit looking for files or whatever, but you're planning to come back to your current directory at some point. In order to save yourself some typing, you decide to use the directory stack. The pushd command works like the cd command in that it puts you in a new directory, but it also stores your original directory in the directory stack. After changing directories, pushd (by default) prints out the contents of the directory stack from left to right:

> pwd

dir1

> pushd

dir2

dir2 dir1

> pwd

dir2

When you're done in dir2, you can go back to the original directory by typing

> popd

dir

Admittedly this procedure would be of limited value if you did most of your work in one directory, but when you're hopping around deep in the directory tree (where path names run to 60+ characters), it can be pretty handy.

The commands relating to the directory stack are described next.

dirs

[-l] [-n|-v]

dirs

-S|-L [filename]

dirs

-c

With no options, the dirs command displays the directory stack.

Example: To display the contents of the directory stack, use

dirs

-c

Clear the stack.

-v

Verbose output. Prints the directory stack, one entry per line, preceded by their stack positions.

-l

Expand entries containing ~ to a full path name.

-n

Wrap entries before the edge of the screen.

-S

Save the directory stack to the specified filename.

-L

Load the directory stack from the specified filename.

popd

[-p] [-l] [-n|-v] [n]

With no arguments, pops the top directory off the stack and returns it. An argument of 'n' discards the nth entry in the stack. The popd command will also display the new directory stack after the pop operation, unless the pushdsilent shell variable is set.

Example: Suppose that your current directory was dir1 and your directory stack (see the previous example "dirs") looked like this:

dir1 dir2 dir3

Recall that the first element of the directory stack is your current working directory, dir1. Therefore, the following command would put you in dir2:

popd dir2

The -l, -n, and -v options to popd are the same as the options to dirs. Specifying a number, n, will discard the nth entry in the stack.

pushd

[-p] [-l] [-n|-v] [n]

With no arguments, pops the top directory off the stack, and returns it. An argument of 'n' discards the nth entry in the stack. The popd command will also display the new directory stack after the pop operation, unless the pushdsilent shell variable is set.

Example: To change to the directory newdir and place the current working directory on the top of the stack, use

pushd newdir

The -l, -n, and -v options to pushd are the same as the options to dirs. Specifying a number, n, will pop the nth entry off the directory stack and change to it.

 



Linux Desk Reference
Linux Desk Reference (2nd Edition)
ISBN: 0130619892
EAN: 2147483647
Year: 2000
Pages: 174
Authors: Scott Hawkins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net