Use of the command varies by context, but there are widespread similarities among variants. The examples below, mostly apply to Unix and Unix-like shells, PowerShell and Command Prompt. To separate the directory names of a path, a program imposes command-line syntax such as a delimiting text between names which varies by program. In particular, Unix and Unix-like shells use a forward slash , Command Prompt uses backslash and PowerShell supports either. For simplicity, paths are shown with forward slashes here. Commonly, a dot is short-hand notation for the working directory and two dots is short-hand for its parent. For example, given working directory , refers to it and refers to . The parent notation is often used to form a relative path that specifies a path that is both up and down the hierarchy. For example: starting with , specifies path .
Common Features that are commonly found for any change directory command: • For a relative path (no leading slash), the path is appended to the working directory path, moving the context deeper into the directory tree hierarchy; for example, if the working directory is , then changes the working directory to • For an absolute path (leading slash), the working directory is replaced with the specified path; for example, sets the working directory to • Moves the directory tree context up one directory; for example, starting at , changes the working directory to • Does not change the working directory but is useful to recover after a directory is recreated by another process • With no arguments, the command changes the working directory to the user's home directory; exception: Command Prompt reports the working directory path
Unix shells Unix-based shells and PowerShell generally share these features: • Changes the working directory to user's home directory • cd ~
username Changes the working directory to the specified user's home directory • Changes the working directory to the previous directory; for example, starting at , executing followed by returns to , which enables toggling between two directories without
pushd and popd Legacy Microsoft shells DOS maintains separate working directories for each
lettered drive, and also has the concept of a current working drive. The command can be used to change the working directory of the working drive or another lettered drive. Typing the drive letter as a command on its own changes the working drive, e.g. ; alternatively, with the switch may be used to change the working drive and that drive's working directory in one step. Modern versions of Windows simulate this behaviour for backwards compatibility under
CMD.EXE. == Example ==