Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Implementations  





2 Usage  





3 Options  



3.1  Unix, Unix-like  





3.2  DOS, OS/2, Windows, ReactOS  







4 Interpreters other than an operating systems shell  





5 See also  





6 References  





7 Further reading  





8 External links  














cd (command)






العربية
Azərbaycanca
Беларуская
Català
Čeština
Dansk
Deutsch
Ελληνικά
Español
فارسی
Français

ि
Hrvatski
Bahasa Indonesia
Italiano
עברית

Magyar
Nederlands

Polski
Português
Română
Русский
Suomi
Türkçe
Українська
Tiếng Vit

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Wikibooks
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

(Redirected from Cd (DOS / Unix Command))

cd / chdir
Developer(s)AT&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

The cd command, also known as chdir (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[edit]

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 cd and chdir commands.[6] The command is also available in the open source MS-DOS emulator DOSBox and in the EFI shell.[7] It is named chdirinHP MPE/iX.[8] The command is analogous to the Stratus OpenVOS change_current_dir command.[9]

cd 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 PowerShellonWindows 7+ and COMMAND.COM on DOS/ Microsoft Windows 3.x-9x/ME.

The system call that effects the command in most operating systems is chdir 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 cd calls the chdir() 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 cd 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 cd 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 ls, rm etc. run in the shell's process. Of course, this is not true for legacy commands which still run in a separate process.

Usage[edit]

Adirectory is a logical section of a file system used to hold files. Directories may also contain other directories. The cd 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 ~) with a file, text.txt, and three subdirectories.

A user's view of the file system in Unix-like systems begins with the home directory (often abbreviated to ~). From there, the tree can spread into more subdirectories and/or files.

If the user's current working directory is the home directory (~), then entering the command ls followed by cd games might produce the following transcript:

user@wikipedia:~$ lsworkreports 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 cd 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 under CMD.EXE.[10]

Note that executing cd from the command line with no arguments has different effects in different operating systems. For example, if cd is executed without arguments in DOS, OS/2, or Windows, the current working directory is displayed (equivalent to Unix pwd). If cd is executed without arguments in Unix, the user is returned to the home directory.

Executing the cd 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 cd command. This is because in Unix, the script is usually executed within a subshell.

Options[edit]

Unix, Unix-like[edit]

DOS, OS/2, Windows, ReactOS[edit]

Interpreters other than an operating systems shell[edit]

In the File Transfer Protocol, the respective command is spelled CWD in the control stream, but is available as cd in most client command-line programs. Some clients also have the lcd 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[edit]

References[edit]

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

    External links[edit]


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Cd_(command)&oldid=1226105279"

    Categories: 
    Windows commands
    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
    Hidden categories: 
    Articles with short description
    Short description is different from Wikidata
    All Wikipedia articles needing clarification
    Wikipedia articles needing clarification from February 2011
     



    This page was last edited on 28 May 2024, at 15:49 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki