Changing the working directory is done in a very similar manner for Windows, OS X, and Linux Ubuntu (along with other Unix-based systems): all of these systems include a cd command for this purpose. However, the options for this command vary slightly between Windows and Unix-based platforms.

Commands

Windows Command Prompt

In Windows, the cd command is a synonym for, and may be used interchangeably with, chdir.

Syntax

cd [path]
cd [/D] {drive:[path]}

The first syntax is used for changing the working directory of the current drive.

  • If path is not specified, then the full path of the current working directory is displayed, and no change is made.
  • If path is specified, it is interpreted in accordance with “Specifying file and directory paths”.

If some element of the specified path contains spaces, then that element (or the entire specified path) must be enclosed within double quotes. (Note that when Command Prompt performs tab-completion, quotes are generated automatically as needed.)

In the second syntax, a drive letter may be specified, with or without a path—e.g. C: or C:\Temp; additionally, the /D option may be specified. Windows maintains a current working directory on each lettered drive, as well as a current drive; the /D option not only changes the working directory on the specified drive, but also changes the current drive to the specified drive.

Examples

cd ..

Changes the working directory to the parent of the current working directory. So, if the working directory before executing the command is C:\Temp, then the working directory after executing the command is C:\ (the root of the C: drive).

cd "\Program Files\Git"

Assuming the current drive is C:, this changes the working directory to C:\Program Files\Git, the default installation directory for the Git software on Windows.

Bash shell (OS X & Ubuntu Terminal, Git Bash, etc.)

Unix-based systems have a few more options for the cd command than Windows does; however, these are not needed for basic usage. In any event, cd --help can be used to explore these options.

Syntax

cd [path]
  • If path is not specified, then the value of the HOME environment variable (usually the current user’s home directory) is used.
  • If path is specified, it is interpreted in accordance with Specifying file and directory paths, with the following variations:
    • If the CDPATH environment variable is defined, path does not begin with / or ~, then the cd command will search for a directory with a path made up of a component of CDPATH and the specified path.
    • If no matching directory is found, the value of path is assumed to be the name of a shell variable, and the value of that shell variable (if it exists) is assumed to be the desired path.

Examples

cd ~/bootcamp

Changes the working directory to the bootcamp subdirectory of the current user’s home directory.

cd /opt/android

Changes the working directory to the android subdirectory of the opt subdirectory of root directory.

Tasks

  1. Use the cd command to change the working directory to the root directory (for Windows, the root directory of the current drive).

  2. Use the cd command again to change the working directory to the bootcamp directory you created during the environment preparation portion of the pre-work. (For OS X and Ubuntu, don’t forget that you can use ~ to refer to your home directory. For Windows, the user home directory is generally located in C:\Users\{user}, where {user} is replaced by your Windows user name.)