Directory paths stack. Elements are pushed onto and popped from the top.
pushd and popd are shellcommands that together allow the user to revert to a previous working directory via the command line. They use a stackdata structure for directory paths. pushd pushes the working directory path onto the stack and changes to the specified directory, and popd pops the most recent item from the stack and changes directory to the popped value.[1][2][3][4]
Behavior varies if no argument is passed to pushd. On Unix, the command swaps the top two directories on the stack, which toggles between them. On Windows, the command lists the paths in the stack except for the current one.
The stack of directory paths can be displayed via the dirs Unix command or Get-Location -stack PowerShell command. The working directory is at the top of the stack.
The first Unix shell to provide a directory stack was Bill Joy's C shell.[citation needed] The syntax for pushing and popping directories is essentially the same as that used now.[7][8]