List of content you will read in this article:
Like Linux, Windows also have a command-line terminal from where you can run various commands for carrying out several Windows-related tasks easily. If you are aware of the Windows terminal command, you will be able to handle the system efficiently. With Windows, you will get several commands that will make your life easier. One of the commonly used commands is the "cd" command that is considered the abbreviation for the "chdir" command.
Like the "cd" command in Linux, it is also used to change the current working directory to another desired directory. In Windows, you will check the current working directory by running the "cwd" command on the terminal. You must know your current working directory, as it will help you resolve the relative paths while changing the directory. In various operating systems, for changing directory, you will get a generic command that is "cd", which stands for changing directory.
This article will check how the "chdir" command will work in Windows operating system. Also, how it will work with various options available. You must know what option is suitable for specific working for which situation.
Description of the Command
The "chdir" command will be responsible for displaying the name of the current directory and allowing you to change from the current directory.
Below are the possible syntax for the "chdir" command that can be used in the Windows operating system.
CHDIR [/D] [drive:][path]
CD [/D] [drive:][path]
The double dot ".." will help specify that you want to navigate to the parent directory or a level immediately above the current directory.
If you want to get the details of the current working directory within a particular drive, you can use the CD drive. Also, if you want to get the current directory and the directory, you can use the CD command without passing any argument. Also, if you're going to change the current drive along with the current working directory for that drive, you can use the /D switch to do so.
Most of the time, the output on the screen will be truncated due to the huge data. If you want the above text executed, then run the cd /? Command on your terminal. Remember that the "chdir" is used as an alias for the "cd" command so you can replace it for all the occurrences.
Checking the current working directory
If you are on your Windows command prompt, there is no need to check the current working directory explicitly. The reason is that the default prompt in the command prompt will display the current working directory along with the drive. But, if you still want to check the current working directory, you can type the "cd" command without any option and argument, as shown below.
From the above example, it is clear that there was no need to check the current working directory in the Windows command prompt as it will be displayed on the prompt by default.
In this article, we will be using the C:\Users as our current working directory and running commands according to this.
Changing the directory
We can change our current working directory to any other desired directory or a different system drive by using various available options.
- Suppose you want to change to another directory from your current working directory within the same drive. In that case, you need to execute the "cd" command along with the absolute path or the relative path of the directory where you want to move.
Before providing the destination path or directory, ensure that the path is an existing directory. Also, that specific directory can be an absolute path or the relative path. If you are using the relative path, it needs to be relative to the current working directory.
You can use the following syntax to change the same drive's directory.
- Suppose you want to change the current working directory to another existing directory within another drive on the system. In that case, you can execute the "cd" command along with the "/D" option and specify the path for the desired directory where you want to move.
Before you specify the path for the directory, make sure you use the absolute path for the directory. Also, the path must have the drive letter being followed by the drive qualifier.
You can use the following syntax for changing the current working directory to another directory present within another drive.
cd /d [path]
- There is another way in the Windows terminal for changing the current working directory to another drive directly without using the "cd" command. You need to use the drive letter followed by the colon sign. This will directly change the path to that drive.
You can consider the following syntax.
In the above example, you can see that the prompt will move to the D drive without any hassle or running various commands in a row. It is done using a single command.
Windows terminal commands are impressive and can do complex tasks easily without running several commands for an easy task. In this guide, you will understand how the "cd" command is used and work around changing from one directory to another.
This command is used with various options that will specify their different working. You must understand how the "cd" command will work with different options and how the absolute and relative paths will work. So go through this guide and learn the basic concepts of this simple command.