Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 目錄切換進階技巧:cd、pushd、popd、dirs 完全指南

編輯:Linux 教學

基本 cd 用法回顧

  • cd:回家目錄
  • cd 子目錄:進入子目錄
  • cd ..:回上層
  • cd /完整/路徑:跳轉絕對路徑
  • pwd:顯示目前目錄

cd -:快速往返兩目錄

輸入 cd - 可在「目前目錄」與「上一個目錄」間切換,極適合來回切換兩個深層路徑。

pushd / popd / dirs:多目錄堆疊切換

建立目錄堆疊,支援多路徑快速輪替。

pushd /usr           # 堆疊:/usr ~
pushd /etc/ssh       # 堆疊:/etc/ssh /usr ~
pushd /etc/rc.d      # 堆疊:/etc/rc.d /etc/ssh /usr ~
dirs                 # 顯示堆疊內容
pushd                # 無參數時,在堆疊頂端兩目錄間切換
pushd +2             # 切換至堆疊第 3 個(索引 2)
dirs -c              # 清空堆疊
popd 目錄名          # 從堆疊移除指定目錄

實務建議

  • 同層級目錄間切換,善用 Shell 歷史(Up 鍵)最快。
  • 跨越完全不同路徑,pushd 效率最高。
  • 預設 Red Hat 系內建 pushd,缺失者可從 ibiblio.org 下載補裝。
Copyright © Windows教程網 All Rights Reserved