pushd and popd
|
|
This article includes a list of references, related reading or external links, but its sources remain unclear because it lacks inline citations. (March 2010) (Learn how and when to remove this template message) |
In computing, pushd and popd are commands used to work with the command line directory stack. They are available on command line interpreters for DOS, Microsoft Windows and Unix-like operating systems, such as 4DOS, Bash, Command Prompt and Windows Powershell.
The pushd command saves the current working directory in memory so it can be returned to at any time, optionally changing to a new directory. The popd command returns to the path at the top of the directory stack. This directory stack is accessed by the command dirs in Unix or Get-Location -stack in Windows PowerShell.
In Windows PowerShell, pushd is a predefined command alias for the Push-Location cmdlet and popd is a predefined command alias for the Pop-Location cmdlet. Both serve basically the same purpose as the Unix-like pushd and popd commands.
The first Unix shell to implement a directory stack was Bill Joy's C shell. The syntax for pushing and popping directories is essentially the same as that used now.[1][2]
Contents
Syntax[edit]
pushd[edit]
pushd [path | ..]
Arguments:
pathThis optional command-line argument specifies the directory to make the current directory. Ifpathis omitted, the path at the top of the directory stack is used, which has the effect of toggling between two directories.
popd[edit]
popd
Examples[edit]
Unix[edit]
[user@server /usr/ports] $ pushd /etc
/etc /usr/ports
[user@server /etc] $ popd
/usr/ports
[user@server /usr/ports] $
DOS Command Prompt[edit]
C:\Users\Admin>pushd AppData\Roaming C:\Users\Admin\AppData\Roaming>popd C:\Users\Admin>
DOS Batch File[edit]
@echo off
rem This batch file deletes all .txt files in a specified directory
pushd %1
del *.txt
popd
echo All text files deleted in the %1 directory
See also[edit]
References[edit]
- Microsoft TechNet Pushd article
- Microsoft TechNet Popd article
- Bash Reference Manual: Directory Stack Builtins
| This Unix-related article is a stub. You can help Wikipedia by expanding it. |
| This Microsoft Windows article is a stub. You can help Wikipedia by expanding it. |

