pushd及popd

维基百科,自由的百科全书

pushd & popd
原作者Bill Joy
開發者多位开源软件商业软件开发者
操作系统Unix, Unix-like, DOS, Windows, ReactOS
平台跨平台
类型命令

pushdpopd 是用于操作命令行目录命令[1][2]它们在DOSMicrosoft WindowsReactOS[3]Unix-like等系统上的4DOSBash[4]C shelltcshHamilton C shellKornShellcmd.exePowerShell命令行解释器中可用。

概览

pushd命令将当前工作目录存储到内存中,以便随时返回。popd命令返回目录栈顶的路径[5][6]此目录栈由Unix命令dirs或 Windows PowerShell的Get-Location -stack访问。

第一个实现目录栈的Unix shell是Bill Joy的C shell。这套Shell下将目录压栈、出栈的语法与现在基本相同。[7][8]

这两个命令都在FreeCOM——即FreeDOS的命令行界面——可用。[9][來源可靠?]

Windows PowerShell下,pushdPush-Locationcmdlet预定义的aliaspopdPop-Locationcmdlet预定义的alias。两者与pushdpopd命令功能基本相同。

语法

Pushd

pushd [path | ..]

参数:

  • 可选命令行参数path指定即将成为“当前目录”的目录。如果path被省略,则会使用目录栈顶的路径,产生在两个目录之间切换的效果。

Popd

popd

示例

Unix-like

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

Microsoft Windows与ReactOS

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

DOS批处理文件

@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

另请参阅

参考文献

  1. ^ Pushd - change directory/folder - Windows CMD - SS64.com. [2021-05-05]. (原始内容存档于2021-05-07). 
  2. ^ Popd - Windows CMD - SS64.com. [2021-05-05]. (原始内容存档于2021-05-06). 
  3. ^ https://github.com/reactos/reactos/blob/master/base/shell/cmd/dirstack.c
  4. ^ Bash Reference Manual: Directory Stack Builtins. [2021-05-05]. (原始内容存档于2021-02-26). 
  5. ^ Microsoft TechNet Pushd article. [2021-05-05]. (原始内容存档于2018-02-03). 
  6. ^ Microsoft TechNet Popd article. [2021-05-05]. (原始内容存档于2018-02-03). 
  7. ^ Chapter 14 – 14.6 The Shells' pushd and popd Commands. [2021-05-05]. (原始内容存档于2020-12-03). 
  8. ^ man tcsh TCSH(1). [2014-11-03]. (原始内容存档于2014-03-10). 
  9. ^ FreeCOM - FreeDOS. [2021-05-05]. (原始内容存档于2021-05-08). 

更多资料

外部链接