MS-DOS is a command-line tool used in Windows operating systems. One of the most basic operations for the command line is changing directory. We can change the current working directory with the
cd command. It may seem very basic and easy but a changing directory with the
cd command provides a lot of different use cases like the change to a parent directory, change the drive, change to the root directory. In this tutorial, we will learn all of them.
cd Command Syntax
cd command has very simple syntax where we provide the path. There is also drive part but it is used very rarely and optionally. We can also use
chdir command like
cdcommand which is the short form of
cd DRIVE:PATH chdir DRIVE:PATH
- `DRIVE` is optional and specifies the drive or partition like C: , D: we can also use lowercase like `c:`, `d:`. DRIVE is generally not used.
- `PATH` is the most important part where the directory names, `.` and `..` are used to specify the path.
cd Command Help
cd is very simple command it has also very little help information for complete usage. We can print help information with
/? like below.
> cd /?
We will start with a simple usage where we will provide the directory we want to change. The given directory is a child directory of the current or current working directory. In this example, we will change to the directory named
Desktop in a row.
> cd Users > cd ismail > cd Desktop
Using Tab To Complete Directory Name
MS-DOS provides tab shortcut to complete directory. If we do not know the whole directory name or it is too long to type we can use
TAB key to list available directories. The completion will be done according to the provided directory name. For example, if we typed
U and press
TAB the directories like
Use will be listed. If we do not type any directory name all currently existing directories will be enumerated alphabetically.
> cd <TAB>
Change Multiple Level/Directories
In the previous example, we have changed the directories one by one with multiple
cd commands. We can also specify multiple directories in a single
cd command. In this example, we will change to the
> cd Users\ismail\Desktop
Change To Directory Name with Spaces
Directory names can be upper case, lower case and provide some special characters like space. While navigating between directories with spaces we have to take care of the directory name. In order to prevent errors, we can use a double quote for the directory name with spaces or for the whole path like below. For example, in order to change directory to the
Program Files we should use
"Program Files" like below.
> cd "Program Files"
Change To Upper/Parent Directory
In order to change one level upper or parent directory typing, the whole path is not feasible. We can use
.. double dot which simply references one level upper or parent directory.
>cd .. >cd "../Program Files"
Change To Two Level Upper/Parent Directory
We can also use
.. to change multiple levels of upper directories. In this example, we will go two-level upper directory with multiple
... We will also use
/ in order to specify the directory level.
> cd ../..
Change To Sibling Directory
We can change to the sibling directory. We will use
.. to go one level upper directory and provide the sibling directory name like
> cd ../Downloads
Change To Root Directory
The root directory is the highest level of the directory for the current partition or drive. We can directly change to the root directory with the
cd\ command without providing extra information.
Print/Display Current Working Directory
While working and changing directories we may be lost in the paths. In some cases, we may need to print the current directory. The current working directory is the path we are currently working and can be printed with the
%cd% environment variable like below. We will also use
echo command to print the current working directory environment variable to the cmd.
> echo %cd%
Windows operating system generally used with multiple partitions or drives. While working with the
cd command navigation between these drives may be required. We can change the current drive or partition just by providing the destination drive or partition name like
e: etc. In the following example, we will change the current working partition to the
> cd d:
Change Drive and Directory
We can also change the current working partition and directory in a single and same command. WEe just need to provide the partition/drive name with the path or directory we want to change. In this example, we will change to the
> cd d:\Backups\2019
Change Directory By Saving Current Path
Navigating the directories in the command line is a very trivial task if there are a lot of different directories to change.
pushdcommand can be used to change a new directory by saving the current path to memory. The saved path can be used with the
popdcommand which is explained below.
>pushd "c:\Program files"
Change Directory To The Saved Path
In the previous example, we have saved the paths and these paths can be easy with the
popd command to navigate.