Skip to content
Related Articles

Related Articles

Cd cmd command
  • Last Updated : 30 Sep, 2020

Cd is the abbreviation or synonym for chdir. It is a command found inside the Windows Command Processor (cmd) that allows for change of the current working directory of a shell instance. The CWD (Current Working Directory) is a path (of a directory) inside the file system, where the shell is currently working. The current working directory is essential for resolving relative paths. Cd is a generic command found in the Command Interpreter of most operating systems.

Description of the Command :
Displays the name of or changes the current directory.

CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]

..   Specifies that you want to change to the parent directory.

Type CD drive: to display the current directory in the specified drive.
Type CD without parameters to display the current drive and directory.
Use the /D switch to change the current drive in addition to changing the current directory for a drive.

  • Some of the output is truncated due to its large length.
  • In order to obtain the above text execute the cd /? command on cmd.
  • It should be noted that chdir is an alias for cd, and therefore can be replaced for all of its occurrences.

Using the Command :

  1. Displaying the Current Working Directory :
    Displaying the current working directory is not generally not required on cmd. This is because the default prompt in cmd displays the Current drive and path (CWD) along with the greater than sign ( > ) at all times ($P$G code). But for the sake of completeness, we would be describing it as well. To display the Current Working Directory, execute the cd command without any arguments.



    Syntax :

    cd

    Apparent from the above output, it is not necessary for us to print the cwd as it is already being displayed by the prompt. Throughout the article, we will be using C:\Users as our CWD.


  2. Changing the CWD :
    We can change the Current Working Directory to different paths in the system. The following are the options –

    1. To a Directory of Current Drive :
    To change the working directory, execute command cd followed by an absolute or relative path of the directory you are wanting to become the CWD. Where the path should qualify the following criteria –

    • The Path should be of a Directory.
    • The Directory should be existing.
    • Path can be absolute or relative. If a relative path is used, then the path should be relative to the CWD.

    Syntax :

    cd [Path]





    2. To a Directory of Another Drive :
    To change the working directory to another drive, execute command cd /D followed by a path to a directory. The path should qualify the following criteria –

    • The path should be absolute.
    • The path should contain the drive letter followed by a drive qualifier (DRIVE_LETTER & COLON).

    Syntax :

    cd /d [Path]



    3. An additional way to change the CWD to another drive without the usage of the cd command is to execute the drive letter followed by a colon.

    Syntax :

    (Drive_Letter):


Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :