如何使用 Windows 命令行更改目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17753986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:43:56  来源:igfitidea点击:

how to change directory using Windows command line

windowscommand-linecmdcommand-prompt

提问by A. K.

I'm using cmd.exe(C:\WINDOWS\System32\cmd.exe) and I have to change my current directory to "D:\temp" i.e. temp folder in the D drive.

我正在使用cmd.exe(C:\WINDOWS\System32\cmd.exe),我必须将当前目录更改为“D:\temp”,即 D 驱动器中的临时文件夹。

When I try to cdnothing happens.

当我尝试cd什么都没有发生。

C:\> cd D:\temp

C:\>

I don't know what else to do here. Even pressing tabkey does not give any hints. I have never got the reason to use cmd.exe until now when I have to. I mostly use Linux for development.

我不知道这里还能做什么。即使按tab键也不会给出任何提示。我从来没有理由使用 cmd.exe 直到现在我必须这样做。我主要使用 Linux 进行开发。

If this helps: I'm on a remote login to another computer and D:\tempin on the remote machine, but so is C:\where I have opened the terminal (cmd.exe).

如果这有帮助:我正在远程登录到另一台计算机并D:\temp在远程计算机上,但C:\我打开终端(cmd.exe)的位置也是如此。

回答by Mark Nenadov

The "cd" command changes the directory, but not what drive you are working with. So when you go "cd d:\temp", you are changing the D drive's directory to temp, but staying in the C drive.

“cd”命令会更改目录,但不会更改您正在使用的驱动器。因此,当您转到“cd d:\temp”时,您将 D 驱动器的目录更改为 temp,但仍保留在 C 驱动器中。

Execute these two commands:

执行这两个命令:

D:
cd temp

That will get you the results you want.

这会让你得到你想要的结果。

回答by Ansgar Wiechers

Another alternative is pushd, which will automatically switch drives as needed. It also allows you to return to the previous directory via popd:

另一种选择是pushd,它将根据需要自动切换驱动器。它还允许您通过以下方式返回上一个目录popd

C:\Temp>pushd D:\some\folder
D:\some\folder>popd
C:\Temp>_

回答by Stephan

cdhas a parameter /d, which will change drive and path with one command:

cd有一个参数/d,它将使用一个命令更改驱动器和路径:

cd /d d:\temp

( see cd /?)

(见cd /?