Working directory: Difference between revisions
Matthiaspaul (talk | contribs) →References: improved ref |
Matthiaspaul (talk | contribs) Cleaned up deprecated HTML by replacing <tt> by <kbd> |
||
Line 1: | Line 1: | ||
⚫ | In [[computing]], the '''working directory''' of a [[process (computing)|process]] is a [[directory (file systems)|directory]] of a hierarchical [[file system]], if any,<ref group="nb" name="NB_DX10"/> dynamically associated with each process. It is sometimes called the '''current working directory (CWD)''', e.g. the [[BSD]] {{man|3|getcwd|FreeBSD||inline}} function, or just '''current directory'''.<ref name="SetCurrentDirectory"/> When the process refers to a file using a simple file name or relative [[path (computing)|path]] (as opposed to a file designated by a full path from a [[root directory]]), the reference is interpreted relative to the current working directory of the process. So for example a process with working directory <kbd>/rabbit-shoes</kbd> that asks to create the file <kbd>foo.txt</kbd> will end up creating the file <kbd>/rabbit-shoes/foo.txt</kbd>. |
||
{{cleanup HTML|date=February 2019}} |
|||
⚫ | In [[computing]], the '''working directory''' of a [[process (computing)|process]] is a [[directory (file systems)|directory]] of a hierarchical [[file system]], if any,<ref group="nb" name="NB_DX10"/> dynamically associated with each process. It is sometimes called the '''current working directory (CWD)''', e.g. the [[BSD]] {{man|3|getcwd|FreeBSD||inline}} function, or just '''current directory'''.<ref name="SetCurrentDirectory"/> When the process refers to a file using a simple file name or relative [[path (computing)|path]] (as opposed to a file designated by a full path from a [[root directory]]), the reference is interpreted relative to the current working directory of the process. So for example a process with working directory < |
||
==In operating systems== |
==In operating systems== |
||
{{further|cd (command)|operating system shell}} |
{{further|cd (command)|operating system shell}} |
||
In most computer file systems, every directory has an entry (usually named "< |
In most computer file systems, every directory has an entry (usually named "<kbd>.</kbd>") which points to the directory itself. |
||
In most [[DOS]] and [[Unix|UNIX]] [[command-line interface|command shell]]s, as well as in the [[Microsoft Windows]] command line interpreters [[cmd.exe]] and [[Windows PowerShell]], the working directory can be changed by using the < |
In most [[DOS]] and [[Unix|UNIX]] [[command-line interface|command shell]]s, as well as in the [[Microsoft Windows]] command line interpreters [[cmd.exe]] and [[Windows PowerShell]], the working directory can be changed by using the <kbd>[[cd (command)|cd]]</kbd> or <kbd>[[cd (command)|chdir]]</kbd> [[command (computing)|command]]s. In [[Unix shell]]s, the <kbd>[[pwd]]</kbd> command outputs a full pathname of the current working directory; the equivalent command in DOS and Windows is <kbd>cd</kbd> without [[parameter (computer science)|arguments]] (whereas in Unix, <kbd>cd</kbd> used without arguments takes the user back to his/her [[home directory]]). |
||
The [[environment variable]] < |
The [[environment variable]] <kbd>PWD</kbd> (in Unix/Linux shells), or the [[pseudo-environment variable]]s <kbd>[[CD (pseudo-environment variable)|CD]]</kbd> (in Windows [[COMMAND.COM]] and [[cmd.exe]], but not in OS/2 and DOS), or <kbd>_CWD</kbd>, <kbd>_CWDS</kbd>, <kbd>_CWP</kbd> and <kbd>_CWPS</kbd> (under [[4DOS]], [[4OS2]], [[4NT (shell)|4NT]] etc.)<ref name="4DOS_8.00_HELP"/> can be used in scripts, so that one need not start an external program. [[Microsoft Windows]] [[file shortcut]]s have the ability to store the working directory. |
||
COMMAND.COM in [[DR-DOS 7.02]] and higher provides < |
COMMAND.COM in [[DR-DOS 7.02]] and higher provides <kbd>ECHOS</kbd>, a variant of the <kbd>[[ECHO (DOS command)|ECHO]]</kbd> command omitting the terminating linefeed.<ref name="Caldera_1998_NEW703"/><ref name="4DOS_8.00_HELP"/> This can be used to create a temporary batchjob storing the current directory in an environment variable like <kbd>CD</kbd> for later use, for example: |
||
ECHOS SET CD=> SETCD.BAT |
ECHOS SET CD=> SETCD.BAT |
||
CHDIR >> SETCD.BAT |
CHDIR >> SETCD.BAT |
||
CALL SETCD.BAT |
CALL SETCD.BAT |
||
DEL SETCD.BAT |
DEL SETCD.BAT |
||
Alternatively, under [[Multiuser DOS]] and [[DR-DOS 7.02]] and higher, various internal and external commands support a parameter < |
Alternatively, under [[Multiuser DOS]] and [[DR-DOS 7.02]] and higher, various internal and external commands support a parameter <kbd>/B</kbd> (for "Batch").<ref name="CCI_1997_HELP"/> 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 <kbd>CHDIR</kbd> would issue a directory path like <code>C:\DOS</code>, a command like <kbd>CHDIR /B</kbd> would issue <code>CHDIR C:\DOS</code> instead, so that <kbd>CHDIR /B > RETDIR.BAT</kbd> would create a temporary batchjob allowing to return to this directory later on. |
||
The current working directory is also displayed by the < |
The current working directory is also displayed by the <kbd>$P</kbd><ref group="nb" name="NB_PROMPT"/> token of the <code>[[PROMPT (DOS command)|PROMPT]]</code> command <ref name="Caldera_1998_USER"/> To keep the prompt short even inside of deep subdirectory structures, the DR-DOS 7.07 COMMAND.COM supports a <kbd>$W</kbd><ref group="nb" name="NB_PROMPT"/> token to display only the deepest subdirectory level. So, where a default <kbd>PROMPT $P$G</kbd> would result f.e. in <code>C:\DOS></code> or <code>C:\DOS\DRDOS></code>, a <kbd>PROMPT $N:$W$G</kbd> would instead yield <code>C:DOS></code> and <code>C:DRDOS></code>, respectively. A similar facility (using <kbd>$W</kbd> and <kbd>$w</kbd>) was added to [[4DOS]] as well.<ref name="4DOS_8.00_HELP"/> |
||
==In programming languages== |
==In programming languages== |
||
Line 40: | Line 39: | ||
{{reflist|group="nb"|refs= |
{{reflist|group="nb"|refs= |
||
<ref group="nb" name="NB_DX10">There are [[operating system]]s that support a [[hierarchical file system]] but have no concept of "working directory"; for example [[Texas Instruments]]' [[DX10 operating system|DX10]], used for the [[TI-990]] series.</ref> |
<ref group="nb" name="NB_DX10">There are [[operating system]]s that support a [[hierarchical file system]] but have no concept of "working directory"; for example [[Texas Instruments]]' [[DX10 operating system|DX10]], used for the [[TI-990]] series.</ref> |
||
<ref group="nb" name="NB_PROMPT">In the same way as < |
<ref group="nb" name="NB_PROMPT">In the same way as <kbd>$O</kbd> works as alternative to <kbd>$P</kbd> under [[DR-DOS]] [[COMMAND.COM]], <kbd>$W</kbd> has an alias <kbd>$Y</kbd> except for that it gets suppressed on [[floppies]] in order to avoid [[critical error]] messages or delays when trying to retrieve the path of a non-inserted floppy.</ref> |
||
}} |
}} |
||
Revision as of 14:38, 8 April 2019
In computing, the working directory of a process is a directory of a hierarchical file system, if any,[nb 1] dynamically associated with each process. It is sometimes called the current working directory (CWD), e.g. the BSD function, or just current directory.[1] When the process refers to a file using a simple file name or relative path (as opposed to a file designated by a full path from a root directory), the reference is interpreted relative to the current working directory of the process. So for example a process with working directory /rabbit-shoes that asks 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 and UNIX command shells, as well as in the Microsoft Windows command line interpreters cmd.exe and Windows PowerShell, the working directory can be changed by using the cd or chdir commands. In Unix shells, the pwd command outputs a full pathname of the current working directory; the equivalent command in DOS and Windows is cd without arguments (whereas in Unix, cd used without arguments takes the user back to his/her home directory).
The environment variable PWD (in Unix/Linux shells), or the pseudo-environment variables CD (in Windows COMMAND.COM and cmd.exe, but not in OS/2 and DOS), or _CWD, _CWDS, _CWP and _CWPS (under 4DOS, 4OS2, 4NT etc.)[2] can be used in scripts, so that one need not start an external program. Microsoft Windows file shortcuts have the ability to store the working directory.
COMMAND.COM in DR-DOS 7.02 and higher provides ECHOS, a variant of the ECHO command omitting the terminating linefeed.[3][2] This can be used to create a temporary batchjob storing the current 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 and DR-DOS 7.02 and higher, various internal and external commands support a parameter /B (for "Batch").[4] 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 current working directory is also displayed by the $P[nb 2] token of the PROMPT
command [5] To keep the prompt short even inside of deep subdirectory structures, the DR-DOS 7.07 COMMAND.COM supports a $W[nb 2] 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 as well.[2]
In programming languages
Most programming languages provide an interface 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, the POSIX function chdir()
effects the system call which changes the working directory.[6] Its argument is a text string 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 is the same function in other languages. In Visual Basic it is usually spelled CHDIR()
.
Unlike the Windows API or POSIX C function, neither the Java programming language nor the Java Virtual Machine supports chdir()
directly;[clarification needed] a change request remained open for over a decade while the team responsible for Java considered the alternatives, though by 2008 the request was denied after only limited support was introduced (affecting first java.lang.Runtime
and later, java.lang.ProcessBuilder
).[7]
See also
- Home directory
- Root directory
- Parent directory
- chroot (Linux systems)
- Load drive (a different, but related concept)
Notes
- ^ There are operating systems that support a hierarchical file system but have no concept of "working directory"; for example Texas Instruments' DX10, used for the TI-990 series.
- ^ a b In the same way as $O works as alternative to $P under DR-DOS COMMAND.COM, $W has an alias $Y except for that it gets suppressed on floppies in order to avoid critical error messages or delays when trying to retrieve the path of a non-inserted floppy.
References
- ^ "Microsoft Windows – SetCurrentDirectory function". Microsoft. Archived from the original on 2018-05-27. Retrieved 2017-05-27.
{{cite web}}
: Unknown parameter|dead-url=
ignored (|url-status=
suggested) (help) - ^ a b c Brothers, Hardin; Rawson, Tom; Conn, Rex C.; Paul, Matthias; Dye, Charles E.; Georgiev, Luchezar I. (2002-02-27). 4DOS 8.00 online help.
- ^ DR-DOS 7.03 WHATSNEW.TXT — Changes from DR-DOS 7.02 to DR-DOS 7.03. Caldera, Inc. 1998-12-24. Archived from the original on 2019-04-08. Retrieved 2019-04-08.
{{cite book}}
: Unknown parameter|dead-url=
ignored (|url-status=
suggested) (help) - ^ CCI Multiuser DOS 7.22 GOLD Online Documentation. Concurrent Controls, Inc. (CCI). 1997-02-10. HELP.HLP.
- ^ DR-DOS 7.02 User Guide. Caldera, Inc. 1998. Archived from the original on 2016-11-04. Retrieved 2013-08-10.
{{cite book}}
: Unknown parameter|dead-url=
ignored (|url-status=
suggested) (help) - ^ "The Open Group Base Specifications Issue 6 and IEEE Std 1003.1" (Issue 6, 2004 ed.). The IEEE and The Open Group. 2004 [2001]. Archived from the original on 2018-02-09. Retrieved 2018-05-27.
{{cite web}}
: Unknown parameter|dead-url=
ignored (|url-status=
suggested) (help) - ^ "JDK-4045688: Add chdir or equivalent notion of changing working directory". Bug Database. Oracle (Sun Microsystems). 2008-08-18 [1997-04-17]. Archived from the original on 2017-10-19. Retrieved 2011-02-20.
{{cite web}}
: Unknown parameter|dead-url=
ignored (|url-status=
suggested) (help)
Further reading
- Chen, Raymond (2010-10-11). "Why does each drive have its own current directory?". The New Old Thing. Microsoft. Archived from the original on 2016-04-12. Retrieved 2017-05-27.
{{cite web}}
: Unknown parameter|dead-url=
ignored (|url-status=
suggested) (help) - Chen, Raymond (2010-05-06). "What are these strange =C: environment variables?". The New Old Thing. Microsoft. Archived from the original on 2018-05-27. Retrieved 2017-05-27.
{{cite web}}
: Unknown parameter|dead-url=
ignored (|url-status=
suggested) (help)
External links
- Working Directory (wd) at Github – a software package that tracks commonly used directories in a bash session