维基百科
pushd及popd
此條目包含過多行話或專業術語,可能需要簡化或提出進一步解釋。 (2021年5月20日) |
pushd
与 popd
是用于操作命令行目录栈的命令。[1][2]它们在DOS、Microsoft Windows、ReactOS[3]和Unix-like等系统上的4DOS、Bash、[4]C shell、tcsh、Hamilton C shell、KornShell、cmd.exe和PowerShell等命令行解释器中可用。
概览 编辑
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下,pushd 是Push-Location
cmdlet预定义的alias,popd 是Pop-Location
cmdlet预定义的alias。两者与pushd
、popd
命令功能基本相同。
语法 编辑
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
另请参阅 编辑
参考文献 编辑
- ^ . [2021-05-05]. (原始内容存档于2021-05-07).
- ^ . [2021-05-05]. (原始内容存档于2021-05-06).
- ^ https://github.com/reactos/reactos/blob/master/base/shell/cmd/dirstack.c
- ^ . [2021-05-05]. (原始内容存档于2021-02-26).
- ^ . [2021-05-05]. (原始内容存档于2018-02-03).
- ^ . [2021-05-05]. (原始内容存档于2018-02-03).
- ^ . [2021-05-05]. (原始内容存档于2020-12-03).
- ^ man tcsh . [2014-11-03]. (原始内容存档于2014-03-10).
- ^ . [2021-05-05]. (原始内容存档于2021-05-08).
更多资料 编辑
- Frisch, Æleen. Windows 2000 Commands Pocket Reference. O'Reilly. 2001. ISBN 978-0-596-00148-3.
- McElhearn, Kirk. The Mac OS X Command Line: Unix Under the Hood. John Wiley & Sons. 2006. ISBN 978-0470113851.
外部链接 编辑
維基教科書中的相關電子教程:Guide to Windows Commands |