In
computing
Computing is any goal-oriented activity requiring, benefiting from, or creating computer, computing machinery. It includes the study and experimentation of algorithmic processes, and the development of both computer hardware, hardware and softw ...
, the working directory of a
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 s ...
is a
directory of a
hierarchical file system
In computing, a hierarchical file system is a file system that uses directories to organize files into a tree structure.
In a hierarchical file system, ''directories'' contain information about both files and other directories, called ''sub ...
, if any,
dynamically associated with the process. It is sometimes called the current working directory (CWD), e.g. the
BSD
The Berkeley Software Distribution (BSD), also known as Berkeley Unix or BSD Unix, is a discontinued Unix operating system developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Berkeley, beginni ...
getcwd function, or just current directory.
When a process refers to a file using a
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
* Desir ...
that is a
relative path, such as a path on a
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 ...
system that does not begin with a
/ (forward slash) or a path on
Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
that does not begin with a
\ (backward slash), the path is interpreted as relative to the process's working directory. So, for example a process on a Unix-like system with working directory
/rabbit-shoes that attempts to create the file
foo.txt will end up creating the file
/rabbit-shoes/foo.txt.
In operating systems
In most computer file systems, every directory has an entry (usually named "
.") which points to the directory itself.
In most
DOS
DOS (, ) is a family of disk-based operating systems for IBM PC compatible computers. The DOS family primarily consists of IBM PC DOS and a rebranded version, Microsoft's MS-DOS, both of which were introduced in 1981. Later compatible syste ...
and
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 ...
command shell
An operating system shell is a computer program that provides relatively broad and direct access to the system on which it runs. The term ''shell'' refers to how it is a relatively thin layer around an operating system.
A shell is generally a ...
s, as well as in the
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
command line interpreters
cmd.exe
cmd.exe, a.k.a. Command Prompt, is a shell program on later versions of Windows ( NT and CE families), OS/2,, eComStation, ArcaOS, and ReactOS. In some versions of Windows ( CE .NET 4.2, CE 5.0 and Embedded CE 6.0) it is referred to as ...
and
Windows 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 langua ...
, the working directory can be changed by using the
CD or
CHDIR command
Command may refer to:
Computing
* Command (computing), a statement in a computer language
* command (Unix), a Unix command
* COMMAND.COM, the default operating system shell and command-line interpreter for DOS
* Command key, a modifier key on A ...
s. In
Unix shell
A Unix shell is a Command-line_interface#Command-line_interpreter, command-line interpreter or shell (computing), shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command languag ...
s, the
pwd
pwd (print working directory) is a shell command that reports the working directory path to standard output.
Although often associated with Unix, its predecessor Multics had a pwd command (which was a short name of the print_wdir command) from ...
command outputs a full pathname of the working directory; the equivalent command in DOS and Windows is
CD or
CHDIR without
arguments
An argument is a series of sentences, statements, or propositions some of which are called premises and one is the conclusion. The purpose of an argument is to give reasons for one's conclusion via justification, explanation, and/or persua ...
(whereas in Unix,
cd used without arguments takes the user back to their
home directory
A home directory is a directory (file systems), file system directory on a multi-user operating system containing computer file, files for a given user (computing), user of the system. The specifics of the home directory (such as its name and loc ...
).
The
environment variable
An environment variable is a user-definable value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the va ...
PWD (in Unix/Linux shells), or the
pseudo-environment variables
CD (in Windows
COMMAND.COM and
cmd.exe
cmd.exe, a.k.a. Command Prompt, is a shell program on later versions of Windows ( NT and CE families), OS/2,, eComStation, ArcaOS, and ReactOS. In some versions of Windows ( CE .NET 4.2, CE 5.0 and Embedded CE 6.0) it is referred to as ...
, but not in OS/2 and DOS), or
_CWD,
_CWDS,
_CWP and
_CWPS (under
4DOS
4DOS is a command-line interpreter by JP Software, designed to replace the default command interpreter COMMAND.COM in MS-DOS and Windows. It was written by Rex C. Conn and Tom Rawson and first released in 1989. Compared to the default, it has ...
,
4OS2
4OS2 is the OS/2 analogue of 4NT and 4DOS by JP Software, Inc. JP Software discontinued 4OS2, TCMDOS2 and TCMD16, making version 3.0, 2.0, 2.0 the final version of these. The code for 4OS2 has been released, and is maintained, first by Sci ...
,
4NT etc.)
can be used in scripts, so that one need not start an external program.
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
file shortcut
In computing, a file shortcut is a handle in a user interface that allows the user to find a file or resource located in a different directory or folder from the place where the shortcut is located. Similarly, an Internet shortcut allows the us ...
s have the ability to store the working directory.
COMMAND.COM in
DR-DOS 7.02 and higher provides
ECHOS, a variant of the
ECHO
In audio signal processing and acoustics, an echo is a reflection of sound that arrives at the listener with a delay after the direct sound. The delay is directly proportional to the distance of the reflecting surface from the source and the lis ...
command omitting the terminating linefeed.
This can be used to create a temporary batchjob storing the working directory in an environment variable like
CD for later use, for example:
ECHOS SET CD=> SETCD.BAT
CHDIR >> SETCD.BAT
CALL SETCD.BAT
DEL SETCD.BAT
Alternatively, under
Multiuser DOS
Multiuser DOS is a real-time multi-user multi-tasking operating system for IBM PC-compatible microcomputers.
An evolution of the older Concurrent CP/M-86, Concurrent DOS and Concurrent DOS 386 operating systems, it was originally developed by ...
and
DR-DOS 7.02 and higher, various internal and external commands support a parameter
/B (for "Batch").
This modifies the output of commands to become suitable for direct command line input (when redirecting it into a batch file) or usage as a parameter for other commands (using it as input for another command). Where
CHDIR would issue a directory path like
C:\DOS
, a command like
CHDIR /B would issue
CHDIR C:\DOS
instead, so that
CHDIR /B > RETDIR.BAT would create a temporary batchjob allowing to return to this directory later on.
The working directory is also displayed by the
$P token of the
PROMPT
command
To keep the prompt short even inside of deep subdirectory structures, the DR-DOS 7.07 COMMAND.COM supports a
$W token to display only the deepest subdirectory level. So, where a default
PROMPT $P$G would result f.e. in
C:\DOS>
or
C:\DOS\DRDOS>
, a
PROMPT $N:$W$G would instead yield
C:DOS>
and
C:DRDOS>
, respectively. A similar facility (using
$W and
$w) was added to
4DOS
4DOS is a command-line interpreter by JP Software, designed to replace the default command interpreter COMMAND.COM in MS-DOS and Windows. It was written by Rex C. Conn and Tom Rawson and first released in 1989. Compared to the default, it has ...
as well.
Under DOS, the absolute paths of the working directories of all logical volumes are internally stored in an array-like data structure called the Current Directory Structure (CDS), which gets dynamically allocated at boot time to hold the necessary number of slots for all logical drives (or as defined by
LASTDRIVE).
This structure imposes a length-limit of 66 characters on the full path of each working directory, and thus implicitly also limits the maximum possible depth of subdirectories.
DOS Plus
DOS Plus (erroneously also known as DOS+) was the first operating system developed by Digital Research's OEM Support Group in Newbury, Berkshire, UK, first released in 1985. DOS Plus 1.0 was based on CP/M-86 Plus combined with the PCM ...
and older issues of DR DOS (up to
DR DOS 6.0, with
BDOS 6.7 in 1991) had no such limitation
due to their implementation using a
DOS emulation on top of a
Concurrent DOS
Multiuser DOS is a real-time multi-user multi-tasking operating system for IBM PC-compatible microcomputers.
An evolution of the older Concurrent CP/M-86, Concurrent DOS and Concurrent DOS 386 operating systems, it was originally developed by ...
- (and thus
CP/M-86
CP/M-86 is a discontinued version of the CP/M operating system that Digital Research (DR) made for the Intel 8086 and Intel 8088. The system commands are the same as in CP/M-80. Executable files used the relocatable .CMD file format. Digital Re ...
-)derived kernel, which internally organized subdirectories as ''relative'' links to parent directories instead of as ''absolute'' paths.
Since
PalmDOS
DR-DOS is a disk operating system for IBM PC compatibles, originally developed by Gary A. Kildall's Digital Research, Inc. and derived from Concurrent PC DOS 6.0, which was an advanced successor of CP/M-86. Upon its introduction in 1988, ...
(with BDOS 7.0) and DR DOS 6.0 (1992 update with BDOS 7.1) and higher switched to use a CDS for
maximum compatibility with DOS programs as well, they faced the same limitations as present in other DOSes.
In programming languages
Most
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s provide an
interface
Interface or interfacing may refer to:
Academic journals
* ''Interface'' (journal), by the Electrochemical Society
* '' Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Linguistics''
* '' Inter ...
to the
file system functions of the operating system, including the ability to set (change) the working directory of the program.
In the
C language
C (''pronounced'' '' – like the letter c'') is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities o ...
, 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 application programming interfaces (APIs), along with comm ...
function
chdir()
effects the
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 changes the working directory.
Its argument is a
text string
In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and the length changed, or it may be fixed (after creation). ...
with a path to the new directory, either absolute or relative to the old one. Where available, it can be called by a process to set its working directory.
There are similar functions in other languages. For example, in
Visual Basic Visual Basic is a name for a family of programming languages from Microsoft. It may refer to:
* Visual Basic (.NET), the current version of Visual Basic launched in 2002 which runs on .NET
* Visual Basic (classic), the original Visual Basic suppo ...
it is usually spelled
CHDIR()
.
In
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
, the working directory can be obtained through the
java.nio.file.Path
interface, or through the
java.io.File
class. The working directory cannot be changed.
See also
*
Home directory
A home directory is a directory (file systems), file system directory on a multi-user operating system containing computer file, files for a given user (computing), user of the system. The specifics of the home directory (such as its name and loc ...
*
Root directory
In a Computing, computer file system, and primarily used in the Unix and Unix-like operating systems, the root directory is the first or top-most Directory (computing), directory in a hierarchy. It can be likened to the trunk of a Tree (data st ...
*
Directory
*
chroot
chroot is a shell (computer), shell command (computing), command and a system call on Unix and Unix-like operating systems that changes the apparent root directory for the current running process and its Child process, children. A program that i ...
(Linux systems)
*
Load drive (a different, but related concept)
*
Long filename
Long filename (LFN) support is Microsoft's backward-compatible extension of the 8.3 filename (short filename) naming scheme used in MS-DOS. Long filenames can be more descriptive, including longer filename extensions such as .jpeg, .tiff, an ...
(LFN)
Notes
References
Further reading
*
*
External links
Working Directory (wd) at Github{spaced ndash a software package that tracks commonly used directories in a
bash session
File system directories