pushd and popd
{{Short description|Shell commands to save and restore the working directory}}
{{lowercase title}}
{{Infobox software
| name = pushd & popd
| logo =
| screenshot =
| screenshot size =
| caption =
| author = Bill Joy
| developer = Various open-source and commercial developers
| released =
| latest release version =
| latest release date =
| operating system = Unix, Unix-like, DOS, Windows, ReactOS
| platform = Cross-platform
| genre = Command
| license =
| website =
}}
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.[https://ss64.com/nt/pushd.html Pushd - change directory/folder - Windows CMD - SS64.com][https://ss64.com/nt/popd.html Popd - Windows CMD - SS64.com][https://technet.microsoft.com/en-us/library/bb490978.aspx Microsoft TechNet Pushd article][https://technet.microsoft.com/en-us/library/bb490969.aspx Microsoft TechNet Popd article]
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,[http://ftp.gnu.org/old-gnu/Manuals/bash-2.05a/html_node/bashref_73.html Bash Reference Manual: Directory Stack Builtins] Command Prompt, PowerShell, C shell, tcsh, 4DOS, Hamilton C shell, KornShell, and FreeCOM.[http://wiki.freedos.org/wiki/index.php/FreeCOM FreeCOM - FreeDOS]
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|date=July 2021}} The syntax for pushing and popping directories is essentially the same as that used now.[http://docstore.mik.ua/orelly/unix/upt/ch14_06.htm Chapter 14 – 14.6 The Shells' pushd and popd Commands]man tcsh {{cite web |url=http://unixhelp.ed.ac.uk/CGI/man-cgi?csh+1 |title=TCSH(1) |access-date=2014-11-03 |url-status=dead |archive-url=https://web.archive.org/web/20140310014443/http://unixhelp.ed.ac.uk/CGI/man-cgi?csh+1 |archive-date=2014-03-10 }}
Examples
=Unix-like=
[user@server /usr/ports] $ pushd /etc
/etc /usr/ports
[user@server /etc] $ popd
/usr/ports
[user@server /usr/ports] $
=Command Prompt and ReactOS=
C:\Users\root>pushd C:\Users
C:\Users>popd
C:\Users\root>
See also
References
{{Reflist|2}}
Further reading
- {{Cite book|first=Æleen|last=Frisch|year=2001|title=Windows 2000 Commands Pocket Reference|publisher=O'Reilly|isbn=978-0-596-00148-3}}
- {{Cite book|author-last=McElhearn|author-first=Kirk|title=The Mac OS X Command Line: Unix Under the Hood|date=2006|publisher=John Wiley & Sons|isbn=978-0470113851}}
External links
{{Wikibooks|Guide to Windows Commands}}
- [https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/pushd pushd | Microsoft Docs]
- [https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/popd popd | Microsoft Docs]
{{Unix commands}}
{{Windows commands}}
Category:Internal DOS commands
Category:Microcomputer software