LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

dirs

directory stack display command

TLDR

Show the current directory stack
$ dirs
copy
Number every entry, which is the form `pushd +N` expects
$ dirs -v
copy
Print absolute paths instead of abbreviating the home directory
$ dirs -l
copy
Print one entry per line, ready to pipe
$ dirs -p
copy
Number the entries and expand the home directory
$ dirs -v -l
copy
Show only the top of the stack, the current directory
$ dirs +0
copy
Show only the oldest entry
$ dirs -0
copy
Count how many directories are stacked
$ dirs -p | wc -l
copy
Empty the stack
$ dirs -c
copy

SYNOPSIS

dirs [-clpv] [+n] [-n]

DESCRIPTION

dirs displays the directory stack managed by pushd and popd. The stack provides a way to remember and return to previously visited directories without typing full paths.The directory stack is a list where the top (leftmost in default view) is the current directory. Each pushd adds to the stack and changes to that directory; popd removes from the stack and returns to the previous directory.Combined with +n and -n notation, you can reference directories by position, enabling quick navigation in complex directory structures.

PARAMETERS

-c

Clear the directory stack.
-l
Display full paths (no ~ abbreviation).
-p
Print one directory per line.
-v
Print with index numbers, one per line.
+n
Display nth entry from left (0 = top).
-n
Display nth entry from right (0 = bottom).

CAVEATS

dirs is a bash/zsh builtin; behavior may vary in other shells. The stack is per-shell and doesn't persist across sessions. POSIX sh doesn't include directory stack functionality. The ~ abbreviation depends on the HOME environment variable.

HISTORY

The directory stack concept originated in the C shell (csh) developed at UC Berkeley in the late 1970s. The pushd, popd, and dirs commands were designed by Bill Joy to simplify navigation. These commands were adopted by bash and other shells, becoming standard tools for power users managing complex directory structures.

SEE ALSO

pushd(1), popd(1), cd(1), pwd(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid