pushd and popd

From Wikipedia, the free encyclopedia
pushd & popd
Original author(s)Bill Joy
Developer(s)Various open-source and commercial developers
Operating systemUnix, Unix-like, DOS, Windows, ReactOS
PlatformCross-platform
TypeCommand

In computing, pushd and popd are commands used to work with the command line directory stack.[1][2] They are available on command-line interpreters such as 4DOS, Bash,[3] C shell, tcsh, Hamilton C shell, KornShell, cmd.exe, and PowerShell for operating systems such as DOS, Microsoft Windows, ReactOS,[4] and Unix-like systems.

Overview[]

The pushd command saves the current working directory in memory so it can be returned to at any time, pushd moves to the parent directory. The popd command returns to the path at the top of the directory stack.[5][6] This directory stack is accessed by the command dirs in Unix or Get-Location -stack in Windows PowerShell.

The first Unix shell to implement 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]

Both commands are available in FreeCOM, the command-line interface of FreeDOS.[9]

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 pushd and popd commands.


Syntax[]

Pushd[]

pushd [path | ..]

Arguments:

  • path This optional command-line argument specifies the directory to make the current directory. If path is omitted, the path at the top of the directory stack is used, which has the effect of toggling between two directories.

Popd[]

popd

Examples[]

Unix-like[]

[user@server /usr/ports] $ pushd /etc
/etc /usr/ports
[user@server /etc] $ popd
/usr/ports
[user@server /usr/ports] $

Microsoft Windows and ReactOS[]

C:\Users\root>pushd C:\Users
C:\Users>popd
C:\Users\root>

DOS batch file[]

@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[]

References[]

  1. ^ Pushd - change directory/folder - Windows CMD - SS64.com
  2. ^ Popd - Windows CMD - SS64.com
  3. ^ Bash Reference Manual: Directory Stack Builtins
  4. ^ https://github.com/reactos/reactos/blob/master/base/shell/cmd/dirstack.c
  5. ^ Microsoft TechNet Pushd article
  6. ^ Microsoft TechNet Popd article
  7. ^ Chapter 14 – 14.6 The Shells' pushd and popd Commands
  8. ^ man tcsh "TCSH(1)". Archived from the original on 2014-03-10. Retrieved 2014-11-03.
  9. ^ FreeCOM - FreeDOS

Further reading[]

  • 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.

External links[]

Retrieved from ""