Pushd及popd

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

pushdpopd 是用于操作命令行目录栈的命令。[1][2]它们在DOS、Microsoft Windows、ReactOS[3]和Unix-like等系统上的4DOS、Bash、[4]C shelltcsh、Hamilton C shell、KornShellcmd.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预定义的alias,popdPop-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). 

更多资料

  • 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
文件系統
程序
  • at
  • bg
  • chroot
  • cron
  • fg
  • kill
  • killall英语killall
  • nice
  • pgrep
  • pkill英语pkill
  • ps
  • pstree英语pstree
  • time
  • top
用户环境
  • clear
  • env
  • exit
  • history英语history (Unix)
  • id
  • logname
  • mesg英语mesg
  • passwd
  • su
  • sudo
  • uptime
  • talk英语talk (software)
  • tput英语tput
  • uname
  • w
  • wall英语wall (Unix)
  • who
  • whoami
  • write英语write (Unix)
文本编辑
  • awk
  • banner英语banner (Unix)
  • basename
  • comm英语comm
  • csplit英语csplit
  • cut
  • diff
  • dirname
  • ed
  • ex
  • fmt英语fmt
  • fold英语fold (Unix)
  • head英语head (Unix)
  • iconv
  • join英语join (Unix)
  • less
  • more
  • nl英语nl (Unix)
  • paste英语paste (Unix)
  • sed
  • sort英语sort (Unix)
  • spell英语spell (Unix)
  • strings英语strings (Unix)
  • tail
  • tr
  • uniq英语uniq
  • vi
  • wc
  • xargs
壳层内建
网络
查找
文档
  • apropos英语apropos (Unix)
  • help英语help (command)
  • man
软件开发
杂项
  • bc
  • cal
  • dc
  • expr
  • lp英语lp (Unix)
  • lpr
  • sleep
  • true和false
  • yes
文件管理导航
  • cd (chdir)
  • dir
  • pushd
  • popd
  • tree
文件管理操作
  • attrib英语ATTRIB
  • cacls
  • cipher
  • compact
  • copy
  • del英语del (command) (erase)
  • deltree英语deltree
  • expand
  • icacls
  • makecab
  • md (mkdir)
  • move英语move (command)
  • rd (rmdir)
  • recover英语recover (command)
  • ren英语ren (command) (rename)
  • replace英语replace (command)
  • Rmdir
  • robocopy英语robocopy
  • xcopy英语XCOPY
磁盘管理
  • chkdsk
  • convert英语convert (command)
  • defrag
  • diskcomp英语diskcomp
  • diskcopy英语diskcopy
  • diskpart英语diskpart
  • fdisk英语fdisk
  • format英语Format (command)
  • label英语label (command)
  • subst英语SUBST
  • scandisk
  • sys英语SYS (command)
  • vol英语vol (command)
  • vssadmin
进程
  • exit
  • kill
  • powercfg英语powercfg
  • runas
  • sc
  • shutdown
  • start英语start (command)
  • taskkill
  • tasklist英语tasklist
注册表
用户环境
  • date
  • mode
  • path
  • set
  • setx
  • time英语TIME (command)
  • title
  • ver英语ver (command)
  • Whoami
文件内容
  • comp英语comp (command)
  • edit英语MS-DOS Editor
  • edlin英语edlin
  • fc英语Microsoft File Compare
  • find英语find (command)
  • findstr
  • print英语PRINT (command)
  • type英语TYPE (DOS command)
脚本
  • choice英语choice (command)
  • clip
  • cscript
  • doskey英语DOSKEY
  • echo
  • for
  • Goto
  • if
  • more
  • pause
  • prompt英语Command-line_interface#Command_prompt
  • rem
网络
维护
启动管理
软件开发
杂项
  • cls
  • help英语help (command)