Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

cd (command)

From Wikipedia, the free encyclopedia
Command to change the working directory
cd / chdir
Thecd command illustration (in a shell session inDebian GNU/Linux)
DevelopersAT&T Bell Laboratories,MetaComCo,Microsoft,IBM,DR,Novell,HP,JP Software,ReactOS Contributors
Operating systemUnix,Unix-like,V,DOS,MSX-DOS,FlexOS,OS/2,TRIPOS,Windows,MPE/iX,Plan 9,Inferno,ReactOS,KolibriOS,SymbOS
PlatformCross-platform
TypeCommand

cd is ashellcommand that changes theworking directory. It is available in many shells and otherapplications that maintain a working directory. In some contexts, the command can perform actions other than change directory. Some environments provide the change directory feature via a different command name such aschdir.

Implementations

[edit]

Generally, a computer system that provides access to ahierarchical file system, provides a change directory command to set the working directory. As this applies to most operating system shells, most support a change directory command, includingUnix andUnix-like (i.e.Linux)shells, andMicrosoft shells includingCommand Prompt andPowerShell.

Other operating systems with shells supporting the command includeOS/2,[1]TRIPOS,[2]AmigaOS[3] (where the command is implied for an inputpath),ReactOS,[4]DOSBox, andUEFI.[5]

Unlike many shell commands that are implemented as separateapplications, change directory is often built-in to the shell because it affects thestate of the shell whereas other commands modify system state outside the shell. If the command was implemented as a separate application, then thechild process would need to modify state in theparent process, but this is often prevented for safety. The command is built-in for most Unix shells (Bourne,tcsh,Bash, etc.), WindowsCommand Prompt andPowerShell, and MS-DOSCOMMAND.COM.

In a shell, the change directory command is typically implemented via asystem call which on Unix and Unix-like systems is typicallyPOSIXchdir() and on Windows is in theWindows API.

The command is also provided in many programs other than shells. In theFile Transfer Protocol, the control stream command isCWD, but the functionality is available ascd in most command-lineclients and some also providelcd for changing thelocal working directory vs. the remote setting. Thenumerical computing environmentsMATLAB andGNU Octave include achange directory command ascd.[10][11]

Use

[edit]

Use of the command varies by context, but there are widespread similarities among variants. The examples below, mostly apply to Unix and Unix-like shells, PowerShell and Command Prompt.

To separate the directory names of a path, a program imposes command-line syntax such as a delimiting text between names – which varies by program. In particular, Unix and Unix-like shells use a forward slash/, Command Prompt uses backslash\ and PowerShell supports either. For simplicity, paths are shown with forward slashes here.

Commonly, a dot is short-hand notation for the working directory and two dots is short-hand for its parent. For example, given working directory/user/bin/tmp,. refers to it and.. refers to/user/bin. The parent notation is often used to form a relative path that specifies a path that is both up and down the hierarchy. For example: starting with/usr/bin/tmp,cd ../../local specifies path/usr/local.

Common

[edit]

Features that are commonly found for any change directory command:

  • cd path/to/dir For a relative path (no leading slash), the path is appended to the working directory path, moving the context deeper into the directory tree hierarchy; for example, if the working directory is/usr, thencd bin changes the working directory to/usr/bin
  • cd /path/to/dir For an absolute path (leading slash), the working directory is replaced with the specified path; for example,cd /bin sets the working directory to/bin
  • cd .. Moves the directory tree context up one directory; for example, starting at/usr/bin/tmp,cd .. changes the working directory to/usr/bin
  • cd . Does not change the working directory but is useful to recover after a directory is recreated by another process
  • cd With no arguments, the command changes the working directory to the user's home directory; exception: Command Prompt reports the working directory path

Unix shells

[edit]

Unix-based shells and PowerShell generally share these features:

  • cd ~ Changes the working directory to user's home directory
  • cd ~username Changes the working directory to the specified user's home directory
  • cd - Changes the working directory to the previous directory; for example, starting at/usr/bin/tmp, executingcd /etc followed bycd - returns to/usr/bin/tmp, which enables toggling between two directories withoutpushd and popd

Legacy Microsoft shells

[edit]

DOS maintains separate working directories for eachlettered drive, and also has the concept of a current working drive. Thecd 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.C:; alternatively,cd with the/d 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 underCMD.EXE.[12]

Example

[edit]
Section of a Unix filesystem showing a user'shome directory (represented as~) with a file and three subdirectories.

Starting with working directory set to the user's home (~), commandls followed bycd games might produce the following:

user@wikipedia:~$lsworkreports games encyclopedia text.txtuser@wikipedia:~$cdgamesuser@wikipedia:~/games$

A similar session in Command Prompt might look like:

C:\> dirworkreports        <DIR>       Wed Oct 9th   9:01games              <DIR>       Tue Oct 8th  14:32encyclopedia       <DIR>       Mon Oct 1st  10:05text        txt           1903 Thu Oct10th  12:43C:\> cd gamesC:\games>

See also

[edit]

References

[edit]
  1. ^"JaTomes Help – OS/2 Commands".www.jatomes.com. Archived fromthe original on 2019-04-14. Retrieved2019-08-11.
  2. ^"Introduction to Tripos"(PDF).Archived(PDF) from the original on 2020-10-21. Retrieved2020-05-01.
  3. ^Rügheimer, Hannes; Spanik, Christian (May 1, 1988).AmigaDOS quick reference. Grand Rapids, Mi : Abacus.ISBN 9781557550491 – via Internet Archive.
  4. ^"Reactos/reactos".GitHub. 3 January 2022.Archived from the original on 31 March 2022. Retrieved11 August 2019.
  5. ^"EFI Shells and Scripting".Intel.Archived from the original on 2013-09-27. Retrieved2013-09-25.
  6. ^Wolverton, Van (2003).Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition.Microsoft Press.ISBN 0-7356-1812-7.
  7. ^"DR DOS 6.0 User Guide Optimisation and Configuration Tips"(PDF). Archived fromthe original(PDF) on 2019-09-30. Retrieved2019-08-13.
  8. ^"MPE/iX Command Reference Manual"(PDF). Archived fromthe original(PDF) on 2018-10-21. Retrieved2018-10-21.
  9. ^"OpenVOS Commands Reference Manual"(PDF).stratadoc.stratus.com.Archived(PDF) from the original on 2019-09-22. Retrieved2020-09-12.
  10. ^"Change current folder – MATLAB cd".www.mathworks.com.
  11. ^"Function Reference: cd".octave.sourceforge.io.Archived from the original on 2019-04-06. Retrieved2019-04-06.
  12. ^"October 11, 2010".The Old New Thing.Archived from the original on October 29, 2020. RetrievedSeptember 12, 2020.

Further reading

[edit]

External links

[edit]
Wikibooks has a book on the topic of:Guide to Windows Commands
The WikibookGuide to Unix has a page on the topic of:Commands
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
Ecosystem
Interpreters
Terminals
File system navigation
File management
Archiving
Disk management
Processes
Registry
User environment
File contents
Scripting
Networking
Maintenance and care
Boot management
Software development
Miscellaneous
Portal:
Retrieved from "https://en.wikipedia.org/w/index.php?title=Cd_(command)&oldid=1336333667"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp