One of the first things you’ll need to learn as you become more familiar with Command Prompt on Windows 10 is how to change directories in the operating system’s file system. There are a few ways you can do this, so we’ll walk you through them.
随着您对Windows 10上的命令提示符更加熟悉,您需要学习的第一件事是如何更改操作系统文件系统中的目录。 您可以通过多种方式进行此操作,因此我们将引导您完成这些操作。
First, type “cmd” in the Windows Search bar to open Command Prompt, and then select “Command Prompt” from the search results.
首先,在Windows搜索栏中键入“ cmd”以打开“命令提示符”,然后从搜索结果中选择“命令提示符”。
With Command Prompt opened, you’re ready to change directories.
打开命令提示符后,就可以更改目录了。
使用拖放方法更改目录 (Change Directories Using the Drag-and-Drop Method)
If the folder you want to open in Command Prompt is on your desktop or already open in File Explorer, you can quickly change to that directory. Type cd
followed by a space, drag and drop the folder into the window, and then press Enter.
如果要在命令提示符下打开的文件夹在桌面上或已经在文件资源管理器中打开,则可以快速切换到该目录。 键入cd
后跟一个空格,将文件夹拖放到窗口中,然后按Enter。
The directory you switched to will be reflected in the command line.
您切换到的目录将反映在命令行中。
在命令提示符下更改目录 (Change Directories Within Command Prompt)
It’s not always convenient to open File Explorer and drag and drop. That’s why it’s cool that you can also type a command to change directories right in Command Prompt.
打开文件资源管理器并拖放并不总是很方便。 这就是为什么您还可以直接在命令提示符下键入命令以更改目录的原因。
Say, for example, you’re in your user folder, and there’s a “Documents” directory in the next file path. You can type the following command in Command Prompt to switch to that directory:
假设您位于用户文件夹中,并且下一个文件路径中有一个“文档”目录。 您可以在命令提示符下键入以下命令以切换到该目录:
cd Documents
cd Documents
Note that this only works if you’re in the immediate file structure. In our case, that would be (user folder) > Documents. In our current directory, we wouldn’t be able to use this method to jump to a directory nested two levels down.
请注意,这仅在您处于直接文件结构中时才有效。 在我们的例子中,该目录为(用户文件夹)>文档。 在当前目录中,我们将无法使用此方法跳转到向下嵌套两个级别的目录。
So, let’s say we’re currently in the user folder and want to go to the “How-To Geek” folder, which is nested in “Documents.” If we try to jump straight to “How-To Geek” without first going to “Documents,” we get the error shown in the image below.
因此,假设我们当前位于用户文件夹中,并且想要转到嵌套在“文档”中的“ How-To Geek”文件夹。 如果我们尝试直接跳到“ How-To Geek”而没有先去“ Documents”,则会收到下图所示的错误。
Let’s take things one directory at a time, for now. As we mentioned previously, we’re currently in our user folder. We type cd Documents
in Command Prompt to visit “Documents.”
现在,让我们一次将一个目录放在一个目录中。 如前所述,我们当前位于用户文件夹中。 我们在命令提示符下键入cd Documents
以访问“ Documents”。
We’re now in the “Documents” folder. To move down another level, we type cd
on the command line followed by the name of that directory.
我们现在位于“文档”文件夹中。 要向下移动一个级别,请在命令行上键入cd
,然后输入该目录的名称。
Now, let’s say we’re back in our user folder and want to skip that extra step and jump two directories down. In our case, this would be our “How-To Geek” folder. We type the following command:
现在,假设我们回到了用户文件夹中,并希望跳过该额外的步骤并向下跳两个目录。 就我们而言,这就是我们的“ How-To Geek”文件夹。 我们输入以下命令:
cd Documents\How-To Geek
This allows us to move two directory levels with one command.
这使我们可以使用一个命令移动两个目录级别。
If you ever go to the wrong directory and want to turn back, type the following command:
如果您进入错误的目录并想返回,请键入以下命令:
This allows you to move up a level.
这使您可以向上移动一个级别。
导航提示 (A Navigation Tip)
If you want to be a bit more efficient with your directory changes, type cd
on the command line, followed by the first few letters of the directory you want. Then, press Tab to autocomplete the directory name.
如果要使目录更改更加有效,请在命令行上键入cd
,然后输入所需目录的前几个字母。 然后,按Tab键自动完成目录名称。
Alternatively, you can type cd
, followed by the first letter of the directory, and then press Tab multiple times until the correct directory appears.
或者,您可以键入cd
,然后键入目录的首字母,然后多次按Tab键,直到出现正确的目录。
查看目录内容 (See Directory Contents)
If you’re ever lost and not sure where to go next, you can view the contents of your current directory by typing dir
on the command line.
如果您迷路了并且不确定下一步要去哪里,可以在命令行上输入dir
来查看当前目录的内容。
This will give you a hint as to which directory to navigate to next.
这将提示您要导航到下一个目录。
翻译自: https://www.howtogeek.com/659411/how-to-change-directories-in-command-prompt-on-windows-10/