dirs - print, save, set, or clear the directory stack


dirs [-l][-n|-v]
dirs -S|-L [filename]
dirs -c


This command is a C-shell built-in command.

The first form prints the directory stack. The top of the stack is at the left and the first directory in the stack is the current directory. With -l, '~' or '~name' in the output, is expanded explicitly to home path name of the home directory for user name. With -n, entries are wrapped before they reach the edge of the screen. With -v, entries are printed one per line, preceded by their stack positions. If more than one of -n or -v is given, -v takes precedence. -p is accepted but does nothing.

With -S, the second form saves the directory stack to filename as a series of cd(1) and pushd(1) commands. With -L, the shell sources filename, which is presumably a directory-stack file saved by the -S option or the savedirs mechanism. In either case, dirsfile is used if filename is not given and ~/.cshdirs is used if dirsfile is unset.

Note that login shells do the equivalent of 'dirs -L' on startup and, if savedirs is set, 'dirs -S' before exiting. Because only ~/.tcshrc is normally sourced before ~/.cshdirs, dirsfile should be set in ~/.tcshrc rather than ~/.login.

The last form clears the directory stack.