my-server
← Wiki Redirected from PUSHD

Pushd and popd

<code>pushd</code> and <code>popd</code> 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. <code>pushd</code> pushes the working directory path onto the stack and changes to the specified directory, and <code>popd</code> pops the most recent item from the stack and changes directory to the popped value.

Behavior varies if no argument is passed to <code>pushd</code>. 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, Command Prompt, PowerShell, C shell, tcsh, 4DOS, Hamilton C shell, KornShell, and FreeCOM.

The stack of directory paths can be displayed via the <code>dirs</code> Unix command or <code>Get-Location -stack</code> 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. The syntax for pushing and popping directories is essentially the same as that used now.

Examples

Unix-like

Command Prompt and ReactOS

See also

References

Further reading

External links