cd/chdir - Changing Directories
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:
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:
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:
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:
/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:
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:
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.