is a
shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
Science Biology
* Seashell, a hard outer layer of a marine ani ...
command that changes the
working directory. It is available in many shells and other
applications that maintain a working directory. In some contexts, the command can perform actions other than change directory. Some environments provide the change directory feature via a different command name such as .
Implementations
Generally, a computer system that provides access to a
hierarchical file system, provides a change directory command to set the working directory. As this applies to most operating system shells, most support a change directory command, including
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
and
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
(i.e.
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
)
shells, and
Microsoft
Microsoft Corporation is an American multinational corporation and technology company, technology conglomerate headquartered in Redmond, Washington. Founded in 1975, the company became influential in the History of personal computers#The ear ...
shells including
Command Prompt and
PowerShell
PowerShell is a shell program developed by Microsoft for task automation and configuration management. As is typical for a shell, it provides a command-line interpreter for interactive use and a script interpreter for automation via a langu ...
.
Other operating systems with shells supporting the command include
OS/2
OS/2 is a Proprietary software, proprietary computer operating system for x86 and PowerPC based personal computers. It was created and initially developed jointly by IBM and Microsoft, under the leadership of IBM software designer Ed Iacobucci, ...
,
TRIPOS
TRIPOS (''TRIvial Portable Operating System'') is a computer operating system. Development started in 1976 at the Computer Laboratory of Cambridge University and it was headed by Dr. Martin Richards. The first version appeared in January 1978 a ...
,
AmigaOS
AmigaOS is a family of proprietary native operating systems of the Amiga and AmigaOne personal computers. It was developed first by Commodore International and introduced with the launch of the first Amiga, the Amiga 1000, in 1985. Early versions ...
(where the command is implied for an input
path),
ReactOS
ReactOS is a Free and open-source software, free and open-source operating system for i586/amd64 personal computers that is intended to be binary-code compatibility, binary-compatible with computer programs and device drivers developed for Wind ...
,
DOSBox
DOSBox is a free and open-source MS-DOS emulator. It supports running programs primarily video games that are otherwise inaccessible since hardware for running a compatible disk operating system (DOS) is obsolete and generally unavailab ...
, and
UEFI.
* On
MS-DOS
MS-DOS ( ; acronym for Microsoft Disk Operating System, also known as Microsoft DOS) is an operating system for x86-based personal computers mostly developed by Microsoft. Collectively, MS-DOS, its rebranding as IBM PC DOS, and a few op ...
, the command is available in version 2 and later
*
DR DOS 6.0 includes the command as both and
* On
HP MPE/iX the command is
* On
OpenVOS, the command is
Unlike many shell commands that are implemented as separate
applications, change directory is often built-in to the shell because it affects the
state
State most commonly refers to:
* State (polity), a centralized political organization that regulates law and society within a territory
**Sovereign state, a sovereign polity in international law, commonly referred to as a country
**Nation state, a ...
of the shell whereas other commands modify system state outside the shell. If the command was implemented as a separate application, then the
child process would need to modify state in the
parent process, but this is often prevented for safety. The command is built-in for most Unix shells (
Bourne,
tcsh,
Bash, etc.), Windows
Command Prompt and
PowerShell
PowerShell is a shell program developed by Microsoft for task automation and configuration management. As is typical for a shell, it provides a command-line interpreter for interactive use and a script interpreter for automation via a langu ...
, and MS-DOS
COMMAND.COM.
In a shell, the change directory command is typically implemented via a
system call
In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
which on Unix and Unix-like systems is typically
POSIX
The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
and on Windows is in the
Windows API.
The command is also provided in many programs other than shells. In the
File Transfer Protocol
The File Transfer Protocol (FTP) is a standard communication protocol used for the transfer of computer files from a server to a client on a computer network. FTP is built on a client–server model architecture using separate control and d ...
, the control stream command is , but the functionality is available as in most command-line
clients and some also provide for changing the
local working directory vs. the remote setting. The
numerical computing environments
MATLAB
MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementat ...
and
GNU Octave
GNU Octave is a scientific programming language for scientific computing and numerical computation. Octave helps in solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly ...
include a
change directory command as
cd
.
Use
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 , then , and then returns to ; this supports 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
Starting with working directory set to the user's home (), command
ls
followed by might produce the following:
user@wikipedia:~$ ls
workreports games encyclopedia text.txt
user@wikipedia:~$ cd games
user@wikipedia:~/games$
A similar session in Command Prompt might look like:
C:\> dir
workreports
Wed Oct 9th 9:01
games Tue Oct 8th 14:32
encyclopedia Mon Oct 1st 10:05
text txt 1903 Thu Oct10th 12:43
C:\> cd games
C:\games>
See also
*
*
*
*
*
References
Further reading
*
*
*
External links
Windows XP > Command-line reference A-Z > Chdir (Cd)
from Microsoft TechNet
*
{{Portalbar, Free and open-source software
Internal DOS commands
File system directories
Inferno (operating system) commands
IBM i Qshell commands
MSX-DOS commands
OS/2 commands
ReactOS commands
Windows administration
Standard Unix programs
Unix SUS2008 utilities