pushd and popd
Original author(s) | Bill Joy |
---|---|
Developer(s) | Various open-source and commercial developers |
Operating system | Unix, Unix-like, DOS, Windows, ReactOS |
Platform | Cross-platform |
Type | Command |

pushd
and popd
are shell commands that together allow the user to revert to a previous working directory via the command line. They use a stack data 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 commands are widely available as builtin commands in many shells, such as Bash,[5] Command Prompt, PowerShell, C shell, tcsh, 4DOS, Hamilton C shell, KornShell, and FreeCOM.[6]
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]
Examples
[edit]Unix-like
[edit][user@server /usr/ports] $ pushd /etc
/etc /usr/ports
[user@server /etc] $ popd
/usr/ports
[user@server /usr/ports] $
Command Prompt and ReactOS
[edit]C:\Users\root>pushd C:\Users
C:\Users>popd
C:\Users\root>
See also
[edit]References
[edit]- ^ Pushd - change directory/folder - Windows CMD - SS64.com
- ^ Popd - Windows CMD - SS64.com
- ^ Microsoft TechNet Pushd article
- ^ Microsoft TechNet Popd article
- ^ Bash Reference Manual: Directory Stack Builtins
- ^ FreeCOM - FreeDOS
- ^ Chapter 14 – 14.6 The Shells' pushd and popd Commands
- ^ man tcsh "TCSH(1)". Archived from the original on 2014-03-10. Retrieved 2014-11-03.
Further reading
[edit]- Frisch, Æleen (2001). Windows 2000 Commands Pocket Reference. O'Reilly. ISBN 978-0-596-00148-3.
- McElhearn, Kirk (2006). The Mac OS X Command Line: Unix Under the Hood. John Wiley & Sons. ISBN 978-0470113851.