This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "PATH" variable – news ·newspapers ·books ·scholar ·JSTOR(August 2014) (Learn how and when to remove this message) |
PATH is anenvironment variable onUnix-likeoperating systems,DOS,OS/2, andMicrosoft Windows, specifying a set ofdirectories where executable programs are located. In general, each executingprocess oruser session has its own PATH setting.
Multics originated the idea of a search path. The earlyUnix shell only looked for program names in/bin, but byVersion 3 Unix the directory was too large and/usr/bin, and a search path, became part of the operating system.[1]
OnPOSIX and Unix-like operating systems, the$PATH variable is specified as a list of one or more directory names separated by colon (:) characters.[2][3]Directories in thePATH-string are not meant to be escaped, making it impossible to have directories with: in their name.[4]
The/bin,/usr/bin, and/usr/local/bin directories are typically included in most users'$PATH setting (although this varies from implementation to implementation). Thesuperuser also typically has/sbin and/usr/sbin entries for easily executingsystem administration commands. The current directory (.) is sometimes included by users as well, allowing programs residing in thecurrent working directory to be executed directly. System administrators as a rule donot include it in$PATH in order to prevent the accidental execution of scripts residing in the current directory, such as may be placed there by a malicioustarbomb. In that case, executing such a program requires specifying an absolute (/home/userjoe/bin/script.sh) or relative path (./script.sh) on the command line.
When a command name is specified by the user or anexec call is made from a program, the system searches through$PATH, examining each directory from left to right in the list, looking for afilename that matches the command name. Once found, the program is executed as achild process of the command shell or program that issued the command.
On DOS, OS/2, and Windows operating systems, the%PATH% variable is specified as a list of one or more directory names separated by semicolon (;) characters.[5]
The Windows system directory (typicallyC:\WINDOWS\system32) is typically the first directory in the path, followed by many (but not all) of the directories for installed software packages. Many programs do not appear in the path as they are not designed to be executed from acommand window, but rather from agraphical user interface. Some programs may add their directory to the front of the PATH variable's content during installation, to speed up the search process and/or override OS commands. In the DOS era, it was customary to add aPATH {program directory};%PATH% orSETPATH={program directory};%PATH% line toAUTOEXEC.BAT.
When a command is entered in a command shell or a system call is made by a program to execute a program, the system first searches thecurrent working directory and then searches the path, examining each directory from left to right, looking for anexecutable filename that matches the command name given. Executable programs havefilename extensions ofEXE orCOM, and batch scripts have extensions ofBAT orCMD. Other executable filename extensions can be registered with the system as well.
Once a matching executable file is found, the systemspawns a new process that runs it.
The PATH variable makes it easy to run commonly used programs located in their own folders. If used unwisely, however, the value of the PATH variable can slow down the operating system by searching too many locations, or invalid locations.
Invalid locations can alsostop services from running altogether, especially the 'Server' service which is usually a dependency for other services within a Windows Server environment.