You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Windows命令提示符返回原目录及快速跳转多级目录的方法问询

Solutions for Quick Directory Jumps & Returning to Original Path in CMD

Great question—this is a super common frustration when moving between Unix shells and Windows CMD. Let’s break down the most practical, native, and customizable solutions to solve both your problems:

1. Use pushd and popd (Native, No Setup Needed)

This is Windows’ built-in answer to Unix-style directory stacking, and it’s perfect for jumping around while keeping your original path accessible:

  • Save your current directory and jump elsewhere: If you’re in a deep path like C:\Users\Greg\Dev\WebApp\frontend\src and need to switch to C:\Temp, run:
    pushd C:\Temp
    
    This pushes your current directory onto a hidden stack, then switches to the new path instantly.
  • Return to your original directory in one step: Whenever you’re ready to go back, just run:
    popd
    
    This pulls the last saved directory from the stack and switches back—no typing out long paths or repetitive ../../..!
  • Bonus: Jump multiple parent directories and save your spot: If you just need to jump up 3 levels (instead of a new path), run pushd ..\..\..—then popd will bring you right back to where you started.

2. Simulate Unix’s cd - with Custom Aliases

If you miss the cd - shortcut to toggle between your current and previous directory, you can set up a custom alias using doskey:

  • Temporary alias (current CMD window only): Run these two commands in your prompt:
    doskey cd=set OLDPWD=%CD% $T cd $*
    doskey cd-=cd "%OLDPWD%"
    
    Now, every time you use cd to switch directories, it saves your old path to the OLDPWD variable. Type cd- (you can adjust the alias to cd - if you prefer, just tweak the doskey command) to jump back to your previous directory.
  • Permanent alias: To make this stick across all CMD windows, add the commands to a .bat file (e.g., cmd_aliases.bat) and set it to run automatically when CMD starts—you can do this via the registry or by adding it to your user’s Startup folder.

3. Quick Multi-Level Parent Directory Jumps

Typing ../../.. gets tedious fast—create a custom up command to jump N levels in one go:

  • Temporary setup: Run this in CMD:
    doskey up=for /l %%i in (1,1,$1) do cd ..
    
    Now, up 2 jumps 2 levels up, up 4 jumps 4 levels, etc.
  • Permanent setup: Add this doskey command to your startup .bat file alongside the cd- alias for a fully customized CMD experience.

内容的提问来源于stack exchange,提问作者Gregory Bishop

火山引擎 最新活动