cd/chdir - Changing Directories

Maintained on

When using an explorer to manipulate files, it is common to navigate to the target folder before performing file operations.

Similarly, in the command prompt, there is the concept of the “current directory.” By navigating to the target directory, you can efficiently perform file operations.

This article explains the cd command for changing directories in the command prompt, from basic usage to setting options, in an easy-to-understand manner.

What is the cd Command?

The cd command stands for Change Directory. By using this command, you can change the current directory in the command prompt.

You can achieve the same result by typing chdir.

The basic usage of the cd command is as follows:

chdir [directory path]
cd [directory path]

For more detailed usage, you can specify the following options:

chdir [/d] [drive:][directory path]
cd [/d] [drive:][directory path]

Display the Current Directory

You can display the current directory by executing the cd command without any arguments.

cd

The output will be as follows:

×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2024 Ribbit App Development All rights reserved.
 
C:\users\user>cd
C:\users\user>
C:\users\user>

Move to a Subdirectory

You can move to a directory by specifying the directory path with the cd command.

cd [directory path]

For example, to move from the C:\users\user directory to the Documents directory, you would write:

cd Documents

The result will be as follows:

×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2024 Ribbit App Development All rights reserved.
 
C:\users\user>cd Documents
C:\users\user\Documents>

Move to the Parent Directory

You can move to the parent directory by specifying .. with the cd command.

cd ..

The result of the execution will be as follows:

×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2024 Ribbit App Development All rights reserved.
 
C:\users\user\Documents>cd ..
C:\users\user>

Specify an Absolute Path

You can move to a directory by specifying an absolute path with the cd command.

cd [drive:][directory path]

For example, to move from the C:\users\user directory to a completely different directory, C:\Windows, you would write:

cd C:\Windows

The result of executing this command will be as follows:

×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2024 Ribbit App Development All rights reserved.
 
C:\users\user>cd C:\Windows
C:\Windows>

/d option - Change Drive

If your computer has a DVD drive or USB memory connected, you need to specify the /d option to move to that drive.

If you run the command without specifying the /d option, no movement will occur, and the current directory will not be changed.

cd /d [drive:][directory path]

For example, to move from the C:\users\user directory to the root directory of the D: drive, you would write:

cd /d D:\

The execution result will be as follows:

×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2024 Ribbit App Development All rights reserved.
 
C:\Windows>cd /d D:\
D:\>
About Moving Between Drives

When moving between drives, you can use the /d option of the cd command, or you can specify the drive name like D: to move.

D:

When the specified directory does not exist

If the directory specified with the cd command does not exist, an error message will be displayed, and the change will not occur.

cd [nonexistent directory path]

The execution result will be as follows:

×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2024 Ribbit App Development All rights reserved.
 
C:\users\user>cd NotExistDirectory
The system cannot find the path specified.
C:\users\user>

Summary

In this article, we explained how to use the cd command to navigate directories in the command prompt.

The cd command has various uses, from basic usage to setting options. Please try it out on the command prompt.

#Command Prompt #Batch Files #Arguments #Command Line #Commands