CHDIR (DOS Command)
   HOME

TheInfoList



OR:

The command, also known as (change directory), is a
command-line A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
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 ** Thin-shell structure Science Biology * Seashell, a hard ou ...
command used to change the current
working directory In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with each process. It is sometimes called the current working directory (CWD), e.g. the BSD getcwd function, or just cur ...
in various
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
s. It can be used in
shell script A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manip ...
s and
batch file Batch may refer to: Food and drink * Batch (alcohol), an alcoholic fruit beverage * Batch loaf, a type of bread popular in Ireland * A dialect term for a bread roll used in North Warwickshire, Nuneaton and Coventry, as well as on the Wirral ...
s.


Implementations

The command has been implemented in operating systems such as
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser 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, and ot ...
,
DOS DOS is shorthand for the MS-DOS and IBM PC DOS family of operating systems. DOS may also refer to: Computing * Data over signalling (DoS), multiplexing data onto a signalling channel * Denial-of-service attack (DoS), an attack on a communicatio ...
, IBM
OS/2 OS/2 (Operating System/2) is a series of computer operating systems, initially created by Microsoft and IBM under the leadership of IBM software designer Ed Iacobucci. As a result of a feud between the two companies over how to position OS/2 ...
, MetaComCo
TRIPOS At the University of Cambridge, a Tripos (, plural 'Triposes') is any of the examinations that qualify an undergraduate for a bachelor's degree or the courses taken by a student to prepare for these. For example, an undergraduate studying mathe ...
,
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 version ...
(where if a bare
path A path is a route for physical travel – see Trail. Path or PATH may also refer to: Physical paths of different types * Bicycle path * Bridle path, used by people on horseback * Course (navigation), the intended path of a vehicle * Desire p ...
is given, cd is ''implied''),
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
,
ReactOS ReactOS is a free and open-source operating system for amd64/i686 personal computers intended to be binary-compatible with computer programs and device drivers made for Windows Server 2003 and later versions of Windows. ReactOS has been noted a ...
, and
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
. 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 ope ...
, it is available in versions 2 and later.
DR DOS 6.0 DR-DOS (written as DR DOS, without a hyphen, in versions up to and including 6.0) is a disk operating system for IBM PC compatibles. Upon its introduction in 1988, it was the first DOS attempting to be compatible with IBM PC DOS and MS-D ...
also includes an implementation of the and commands. The command is also available in the
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
MS-DOS
emulator In computing, an emulator is Computer hardware, hardware or software that enables one computer system (called the ''host'') to behave like another computer system (called the ''guest''). An emulator typically enables the host system to run so ...
DOSBox DOSBox is a free and open-source emulator which runs software for MS-DOS compatible disk operating systems—primarily video games. It was first released in 2002, when DOS technology was becoming obsolete. Its adoption for running DOS games i ...
and in the EFI shell. It is named in HP MPE/iX. The command is analogous to the
Stratus Stratus may refer to: Weather *Stratus cloud, a cloud type **Nimbostratus cloud, a cloud type **Stratocumulus cloud, a cloud type **Altostratus cloud, a cloud type **Altostratus undulatus cloud, a cloud type **Cirrostratus cloud, a cloud type Mus ...
OpenVOS Stratus VOS (Virtual Operating System) is a proprietary operating system running on Stratus Technologies fault-tolerant computer systems. VOS is available on Stratus's ftServer and Continuum platforms. VOS customers use it to support high-volume ...
command. is frequently included built directly into a command-line interpreter. This is the case in most of the
Unix shell A Unix shell is a command-line Interpreter (computing), interpreter or shell (computing), shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting langua ...
s (
Bourne shell The Bourne shell (sh) is a Shell (computing), shell Command-line interface#Command-line interpreter, command-line interpreter for computer operating systems. The Bourne shell was the default Unix shell, shell for Version 7 Unix. Unix-like syste ...
,
tcsh tcsh ( “tee-see-shell”, “tee-shell”, or as “tee see ess aitch”, tcsh) is a Unix shell based on and backward compatible with the C shell (csh). Shell It is essentially the C shell with programmable command-line completion, command-l ...
,
bash Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "Bash" ('' ...
, etc.),
cmd.exe Command Prompt, also known as cmd.exe or cmd, is the default command-line interpreter for the OS/2, eComStation, ArcaOS, Microsoft Windows (Windows NT family and Windows CE family), and ReactOS operating systems. On Windows CE .NET 4.2, Wind ...
on Microsoft
Windows NT Windows NT is a proprietary graphical operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems sc ...
/
2000 File:2000 Events Collage.png, From left, clockwise: Protests against Bush v. Gore after the 2000 United States presidential election; Heads of state meet for the Millennium Summit; The International Space Station in its infant form as seen from ...
+ and
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
on
Windows 7 Windows 7 is a major release of the Windows NT operating system developed by Microsoft. It was released to manufacturing on July 22, 2009, and became generally available on October 22, 2009. It is the successor to Windows Vista, released nearly ...
+ and
COMMAND.COM COMMAND.COM is the default command-line interpreter for MS-DOS, Windows 95, Windows 98 and Windows Me. In the case of DOS, it is the default user interface as well. It has an additional role as the usual first program run after boot (init proc ...
on DOS/ Microsoft
Windows 3.x Windows 3.x means either of, or all of the following versions of Microsoft Windows: * Windows 3.0 * Windows 3.1x Windows 3.1 is a major release of Microsoft Windows. It was released to manufacturing on April 6, 1992, as a successor to Windo ...
- 9x/ ME. The
system call In computing, a system call (commonly abbreviated to 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, acc ...
that effects the command in most operating systems is that is defined by
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 both the system- and user-level application programming interf ...
. Command line shells on Windows usually use the
Windows API The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. The name Windows API collectively refers to several different platform implementations th ...
to change the current working directory, whereas on Unix systems calls the
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 both the system- and user-level application programming interf ...
C function. This means that when the command is executed, no new process is created to migrate to the other directory as is the case with other commands such as ls. Instead, the shell itself executes this command. This is because, when a new
process A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic. Things called a process include: Business and management *Business process, activities that produce a specific se ...
is created,
child process A child process in computing is a process created by another process (the parent process). This technique pertains to multitasking operating systems, and is sometimes called a subprocess or traditionally a subtask. There are two major procedures ...
inherits the directory in which the
parent process In computing, a parent process is a process that has created one or more child processes. Unix-like systems In Unix-like operating systems, every process except (the swapper) is created when another process executes the fork() system call. Th ...
was created. If the command inherits the parent process' directory, then the objective of the command cd will never be achieved.
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-sourc ...
, Microsoft's object-oriented command line shell and
scripting language A scripting language or script language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system. Scripting languages are usually interpreted at runtime rather than compiled. A scripting ...
, executes the command (''cmdlet'') within the shell's process. However, since PowerShell is based on the
.NET Framework The .NET Framework (pronounced as "''dot net"'') is a proprietary software framework developed by Microsoft that runs primarily on Microsoft Windows. It was the predominant implementation of the Common Language Infrastructure (CLI) until bein ...
and has a different architecture than previous shells, all of PowerShell's cmdlets like , etc. run in the shell's process. Of course, this is not true for legacy commands which still run in a separate process.


Usage

A
directory Directory may refer to: * Directory (computing), or folder, a file system structure in which to store computer files * Directory (OpenVMS command) * Directory service, a software application for organizing information about a computer network's u ...
is a logical section of a
file system In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
used to hold files. Directories may also contain other directories. The command can be used to change into a subdirectory, move back into the parent directory, move all the way back to the
root directory In a computer file system, and primarily used in the Unix and Unix-like operating systems, the root directory is the first or top-most directory in a hierarchy. It can be likened to the trunk of a tree, as the starting point where all branches ...
or move to any given directory. Consider the following subsection of a Unix filesystem, which shows a user's
home directory A home directory is a file system directory on a multi-user operating system containing files for a given user of the system. The specifics of the home directory (such as its name and location) are defined by the operating system involved; for ...
(represented as ) with a file, , and three subdirectories. If the user's current working directory is the home directory (), then entering the command ls followed by might produce the following transcript: user@wikipedia:~$ ls workreports games encyclopedia text.txt user@wikipedia:~$ cd games user@wikipedia:~/games$ The user is now in the "games" directory. A similar session in DOS (though the concept of a "home directory" may not apply, depending on the specific version) would look like this: 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> 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 Command Prompt, also known as cmd.exe or cmd, is the default command-line interpreter for the OS/2, eComStation, ArcaOS, Microsoft Windows (Windows NT family and Windows CE family), and ReactOS operating systems. On Windows CE .NET 4.2, Wind ...
. Note that executing from the command line with no arguments has different effects in different operating systems. For example, if is executed without arguments in DOS, OS/2, or Windows, the current
working directory In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with each process. It is sometimes called the current working directory (CWD), e.g. the BSD getcwd function, or just cur ...
is displayed (equivalent to Unix
pwd In Unix-like and some other operating systems, the pwd command (''print working directory'') writes the full pathname of the current working directory to the standard output. Implementations Multics had a pwd command (which was a short name of ...
). If is executed without arguments in Unix, the user is returned to the home directory. Executing the command within a script or batch file also has different effects in different operating systems. In DOS, the caller's current directory can be directly altered by the
batch file Batch may refer to: Food and drink * Batch (alcohol), an alcoholic fruit beverage * Batch loaf, a type of bread popular in Ireland * A dialect term for a bread roll used in North Warwickshire, Nuneaton and Coventry, as well as on the Wirral ...
's use of this command. In
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser 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, and ot ...
, the caller's current directory is not altered by the script's invocation of the command. This is because in Unix, the script is usually executed within a subshell.


Options


Unix, Unix-like

* by itself or will always put the user in their home directory. * will leave the user in the same directory they are currently in (i.e. the current directory won't change). This can be useful if the user's shell's internal code can't deal with the directory they are in being recreated; running will place their shell in the recreated directory. * cd ~''username'' will put the user in the username's home directory. * (without a ) will put the user in a subdirectory; for example, if they are in , typing will put them in , while puts them in . * will move the user up one directory. So, if they are , moves them to , while moves them to (i.e. up two levels). The user can use this indirection to access subdirectories too. So, from , they can use to go to * will switch the user to the previous directory. For example, if they are in , and go to , they can type to go back to . The user can use this to toggle back and forth between two directories.


DOS, OS/2, Windows, ReactOS

* ''no attributes'' print the full
path A path is a route for physical travel – see Trail. Path or PATH may also refer to: Physical paths of different types * Bicycle path * Bridle path, used by people on horseback * Course (navigation), the intended path of a vehicle * Desire p ...
of the current directory. * Print the final directory stack, just like dirs. * Entries are wrapped before they reach the edge of the screen. * entries are printed one per line, preceded by their stack positions. * (DOS and Windows only) returns to the root dir. Consequently, command always takes the user to the named subdirectory on the ''root directory'', regardless of where they are located when the command is issued.


Interpreters other than an operating systems shell

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 data ...
, the respective command is spelled in the control stream, but is available as in most
client Client(s) or The Client may refer to: * Client (business) * Client (computing), hardware or software that accesses a remote service on another computer * Customer or client, a recipient of goods or services in return for monetary or other valuable ...
command-line programs. Some clients also have the for changing the working directory locally. 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, implementation ...
and
GNU Octave GNU Octave is a high-level programming language primarily intended for scientific computing and numerical computation. Octave helps in solving linear and nonlinear problems numerically, and for performing other numerical experiments using a langu ...
include a cd function with similar functionality. The command also pertains to command-line interpreters of various other application software.


See also

*
Directory structure In computing, a directory structure is the way an operating system arranges Computer file, files that are accessible to the user. Files are typically displayed in a hierarchical tree structure. File names and extensions A filename is a string use ...
*
pushd and popd In computing, pushd and popd are commands used to work with the command line directory stack. They are available on command-line interpreters such as 4DOS, Bash, C shell, tcsh, Hamilton C shell, KornShell, cmd.exe, and PowerShell for op ...
*
chroot A chroot on Unix and Unix-like operating systems is an operation that changes the apparent root directory for the current running process and its children. A program that is run in such a modified environment cannot name (and therefore normally ...
*
List of command-line interpreters In computing, a command-line interpreter, or command language interpreter, is a blanket term for a certain class of programs designed to read lines of text entered by a user, thus implementing a command-line interface. Operating system shells ...


References


Further reading

* * *


External links


Windows XP > Command-line reference A-Z > Chdir (Cd)
from
Microsoft TechNet Microsoft TechNet was a Microsoft web portal and web service for IT professionals. It included a library containing documentation and technical resources for Microsoft products, a learning center which provides online training, discussion forums ...
* {{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