Английская Википедия:Cd (command)
Шаблон:Short description Шаблон:Lowercase Шаблон:Infobox software The Шаблон:Code command, also known as Шаблон:Code (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.
Implementations
The command has been implemented in operating systems such as Unix, DOS, IBM OS/2,[1] MetaComCo TRIPOS,[2] AmigaOS[3] (where if a bare path is given, cd is implied), Microsoft Windows, ReactOS,[4] and Linux. On MS-DOS, it is available in versions 2 and later.[5] DR DOS 6.0 also includes an implementation of the Шаблон:Code and Шаблон:Code commands.[6] The command is also available in the open source MS-DOS emulator DOSBox and in the EFI shell.[7] It is named Шаблон:Code in HP MPE/iX.[8] The command is analogous to the Stratus OpenVOS Шаблон:Code command.[9]
Шаблон:Code is frequently included built directly into a command-line interpreter. This is the case in most of the Unix shells (Bourne shell, tcsh, bash, etc.), cmd.exe
on Microsoft Windows NT/2000+ and Windows PowerShell on Windows 7+ and COMMAND.COM
on DOS/ Microsoft Windows 3.x-9x/ME.
The system call that effects the command in most operating systems is Шаблон:Code that is defined by POSIX.
Command line shells on Windows usually use the Windows API to change the current working directory, whereas on Unix systems Шаблон:Code calls the Шаблон:Code POSIX 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 is created, child process inherits the directory in which the parent process was created. If the Шаблон:Code command inherits the parent process' directory, then the objective of the command cd will never be achieved.
Windows PowerShell, Microsoft's object-oriented command line shell and scripting language, executes the Шаблон:Code command (cmdlet) within the shell's process. However, since PowerShell is based on the .NET Framework and has a different architecture than previous shells, all of PowerShell's cmdlets like Шаблон:Code, [[rm (Unix)|Шаблон:Code]] 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 is a logical section of a file system used to hold files. Directories may also contain other directories. The Шаблон:Code command can be used to change into a subdirectory, move back into the parent directory, move all the way back to the root directory or move to any given directory.
Consider the following subsection of a Unix filesystem, which shows a user's home directory (represented as Шаблон:Code) with a file, Шаблон:Code, and three subdirectories.
If the user's current working directory is the home directory (Шаблон:Code), then entering the command ls
followed by Шаблон:Code 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Шаблон:Vague) would look like this:
C:\> dir workreports <DIR> Wed Oct 9th 9:01 games <DIR> Tue Oct 8th 14:32 encyclopedia <DIR> 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 Шаблон:Code 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. Шаблон:Code; alternatively, Шаблон:Code with the Шаблон:Code 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.[10]
Note that executing Шаблон:Code from the command line with no arguments has different effects in different operating systems. For example, if Шаблон:Code is executed without arguments in DOS, OS/2, or Windows, the current working directory is displayed (equivalent to Unix pwd
). If Шаблон:Code is executed without arguments in Unix, the user is returned to the home directory.
Executing the Шаблон:Code 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's use of this command. In Unix, the caller's current directory is not altered by the script's invocation of the Шаблон:Code command. This is because in Unix, the script is usually executed within a subshell.
Options
Unix, Unix-like
- Шаблон:Code by itself or Шаблон:Code will always put the user in their home directory.
- Шаблон:Code 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 Шаблон:Code will place their shell in the recreated directory.
cd ~username
will put the user in the username's home directory.- Шаблон:Code (without a Шаблон:Code) will put the user in a subdirectory; for example, if they are in Шаблон:Code, typing Шаблон:Code will put them in Шаблон:Code, while Шаблон:Code puts them in Шаблон:Code.
- Шаблон:Code will move the user up one directory. So, if they are Шаблон:Code, Шаблон:Code moves them to Шаблон:Code, while Шаблон:Code moves them to Шаблон:Code (i.e. up two levels). The user can use this indirection to access subdirectories too. So, from Шаблон:Code, they can use Шаблон:Code to go to Шаблон:Code
- Шаблон:Code will switch the user to the previous directory. For example, if they are in Шаблон:Code, and go to Шаблон:Code, they can type Шаблон:Code to go back to Шаблон:Code. The user can use this to toggle back and forth between two directories without pushd and popd.
DOS, OS/2, Windows, ReactOS
- no attributes print the full path of the current directory.
- Шаблон:Code Print the final directory stack, just like dirs.
- Шаблон:Code Entries are wrapped before they reach the edge of the screen.
- Шаблон:Code entries are printed one per line, preceded by their stack positions.
- Шаблон:Code (DOS and Windows only) returns to the root dir. Consequently, command Шаблон:Code 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 respective command is spelled Шаблон:Code in the control stream, but is available as Шаблон:Code in most client command-line programs. Some clients also have the Шаблон:Code for changing the working directory locally.
The numerical computing environments MATLAB and GNU Octave include a cd
function with similar functionality.[11][12] The command also pertains to command-line interpreters of various other application software.
See also
References
Further reading
External links
Шаблон:Wikibooks Шаблон:Wikibooks
Шаблон:Unix commands Шаблон:Windows commands Шаблон:Portalbar
- Английская Википедия
- Страницы с неработающими файловыми ссылками
- 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
- Страницы, где используется шаблон "Навигационная таблица/Телепорт"
- Страницы с телепортом
- Википедия
- Статья из Википедии
- Статья из Английской Википедии