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

更多資料[編輯]

外部連結[編輯]