Hints for using the CD command

10 users found this article helpful

The CD command has already been mentioned in other articles: Command line syntax, Displaying help for commands, and Delimiters, spaces, and special characters. This article intends to give a more complete explanation of how to use the CD command. Some of this information is not obvious when you view the help text available in the Command Prompt.

The CD command is used to change directories, which means it moves the command prompt into a different folder. Please look at the picture below to see that, in this case, the command prompt is in the Name subdirectory, which is inside the Users directory, which is on the C drive.

Command Prompt window

If you plan to run a number of commands involving files in another directory, you will either need to enter the path to this other directory whenever referring to the files in it, or you will need to change directories in the command prompt window.

For example, let us say that you will be working with files saved in a directory named Letters which was created in the Documents directory. Since these two are both subdirectories below the path of the current directory (C:\User\Name) you can use the CD command to change directories in one of two ways.

Change to the Letters directory in 2 steps

Note: The Command Prompt does not care if you use capital or lower case letters.

Change to the Letters directory in 1 step

The backslash character in the example above represents a folder (directory), so that this command has told the Command Prompt to move down into the Documents subdirectory and continue into the Letters subdirectory.

If you want to move to a higher subdirectory, you can use CD.. which will move the command prompt to the subdirectory that is one higher than its current location. If you started where we just ended (the Letters subdirectory) and you used CD.. you would end up in the Documents subdirectory. If you used it twice, you would find yourself in the Name subdirectory.

If you want to move to a subdirectory of another parent directory or if you want to move up to the root of the drive, you would want to use CD \ (please note that there is a space between CD and the backslash character). If you type CD \ and press Enter, you will then be at the root of the current drive.

Starting back in the Letters subdirectory, if you wanted to move directly from there to C:\Invoices\January you would type CD \Invoices\January and press Enter.

In the example above the first backslash instructs the Command Prompt to begin at the root of the drive, move into the Invoices directory and then continue into the January subdirectory.

See also: Command Line Basics articles

Was this article helpful?

Tell us how we can improve it.