cd (command)

Upload: totoymola8

Post on 03-Jun-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 CD (Command)

    1/5

    cd (command)From Wikipedia, the free encyclopedia

    The cdcommand, also known as chdir(change directory), is a command-line OS shecommand used to change the current working directory in operating systems such asUnix, DOS, OS/2, AmigaOS (where if a bare path is given, cd is implied), Windows, andLinux. It is also available for use in shell scripts and batch files. The system call that

    effects the command in most operating systems is chdir(2) that is defined by POSIX.

    Contents

    1 Usage2 Options (version specific)3 How it works4 Interpreters other than an operating systems shell

    5 See also6 References7 External links

    Usage

    A directory is a logical section of a file system used to hold files. Directories may alsocontain other directories. The cdcommand can be used to change into a subdirectory

    move back into the parent directory, move all the way back to the root directory ormove toany given directory.

    Consider the following subsection of a Unix filesystem, which shows a user's homedirectory (represented as ~) with a file (text.txt) and three subdirectories.

    http://en.wikipedia.org/wiki/Home_directoryhttp://en.wikipedia.org/wiki/Home_directoryhttp://en.wikipedia.org/wiki/Root_directoryhttp://en.wikipedia.org/wiki/Directory_(file_systems)http://en.wikipedia.org/wiki/Home_directoryhttp://en.wikipedia.org/wiki/Root_directoryhttp://en.wikipedia.org/wiki/File_systemhttp://en.wikipedia.org/wiki/Directory_(file_systems)http://en.wikipedia.org/wiki/POSIXhttp://en.wikipedia.org/wiki/Chdirhttp://en.wikipedia.org/wiki/System_callhttp://en.wikipedia.org/wiki/Batch_filehttp://en.wikipedia.org/wiki/Shell_scripthttp://en.wikipedia.org/wiki/Linuxhttp://en.wikipedia.org/wiki/Microsoft_Windowshttp://en.wikipedia.org/wiki/Path_(computing)http://en.wikipedia.org/wiki/AmigaOShttp://en.wikipedia.org/wiki/OS/2http://en.wikipedia.org/wiki/DOShttp://en.wikipedia.org/wiki/Unixhttp://en.wikipedia.org/wiki/Operating_systemhttp://en.wikipedia.org/wiki/Working_directoryhttp://en.wikipedia.org/wiki/Operating_system_shellhttp://en.wikipedia.org/wiki/Command-line_interface
  • 8/12/2019 CD (Command)

    2/5

    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 thecommand lsfollowed by cd gamesmight produce the following transcript:

    user@wikipedia:~$ lsworkreports games encyclopedia text.txtuser@wikipedia:~$ cdgamesuser@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) would look like this:

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

    C:\> cd gamesC:\games>

    DOS maintains separate working directories for each lettered drive, and also has theconcept of a current working drive. The cdcommand can be used to change theworking directory of the working drive or another lettered drive. Typing the driveletter as a command on its own changes the working drive, e.g. C:; alternatively, cd

    http://en.wikipedia.org/wiki/Drive_letter_assignmenthttp://en.wikipedia.org/wiki/Dir_(command)http://en.wikipedia.org/wiki/Lshttp://en.wikipedia.org/wiki/File:Chdir_example.png
  • 8/12/2019 CD (Command)

    3/5

    with the /dswitch may be used to change the working drive and that drive's workingdirectory in one step. Modern versions of Windows simulate this behaviour for

    backwards compatibility under cmd.exe.[1]

    Note that executing cdfrom the command line with no arguments has differenteffects in different operating systems. For example, if cdis executed withoutarguments in DOS, OS/2, or Windows, the current working directory is displayed. If cd

    is executed without arguments in Unix, the user is returned to the home directory.Executing the cdcommand within a script or batch file also has different effects indifferent operating systems. In DOS, the caller's current directory can be directlyaltered by the batch file's use of this command. In Unix, the caller's current directoryis not altered by the script's invocation of the cdcommand. This is because in Unix, thscript is usually executed within a subshell.

    Options (version specific)

    no attributesReturn to the home directory (UNIX) or print the full path of thecurrent directory (DOS and Windows)-pPrint the final directory stack, just like dirs.-l'~'(UNIX only) or '~name'(UNIX only) in the output is expanded explicitly tohome or the pathname of the home directory for user name.-nEntries are wrapped before they reach the edge of the screen.-ventries are printed one per line, preceded by their stack positions.cd\(DOS and Windows only) returns to the root dir. Consequently, commandcd\subdiralways takes the user to the named subdirectory on the root directoryregardless of where they are located when the command is issued.

    Application of some options (UNIX)[2]

    "cd" by itself or cd ~ will always put you in your home directory.

    "cd ." will leave you in the same directory you are currently in (i.e. your currentdirectory won't change)

    "cd ~username" will put you in username's home directory.

    "cd dir" (without a /) will put you in a subdirectory. for example, if you are in /usr,

    typing cd bin will put you in /usr/bin, while cd /bin puts you in /bin.

    "cd .." will move you up one directory. So, if you are /usr/bin/tmp, cd .. moves you to/usr/bin, while cd ../.. moves you to /usr (i.e. up two levels). You can use this indirectioto access subdirectories too. So, from /usr/bin/tmp, you can use cd ../../local to go to/usr/local.

    http://en.wikipedia.org/wiki/Path_(computing)http://en.wikipedia.org/wiki/Path_(computing)http://en.wikipedia.org/wiki/Child_processhttp://en.wikipedia.org/wiki/Unixhttp://en.wikipedia.org/wiki/Batch_filehttp://en.wikipedia.org/wiki/Working_directoryhttp://en.wikipedia.org/wiki/Command_Prompt
  • 8/12/2019 CD (Command)

    4/5

    "cd -" will switch you to the previous directory (UNIX only). For example, if you are in/usr/bin/tmp, and go to /etc., you can type cd - to go back to /usr/bin/tmp. You can usethis to toggle back and forth between two directories.

    Howit works

    cdis frequently included built directly into a command-line interpreter. This is the cas

    in mostof the Unix shells (Bourne shell, tcsh, bash, etc.), cmd.exeand WindowsPowerShell on Windows and COMMAND.COMon DOS.

    Command line shells on Windows usually use the Windows API to change the currentworkingdirectory, whereas on Unix systems cdcalls the chdir()POSIX C function. Thimeans that when the command is executed, no new process is created to migrate tothe otherdirectory as is the case with other commands such as ls. Instead, the shellitself executes this command. This is because, when a new process is created, childprocessinherits the directory in which the parent process was created. If the cdcommand inherits the parent process' directory, then the objective of the command

    cd will never be achieved.

    WindowsPowerShell, Microsoft's object-oriented command line shell and scriptinglanguage, executes the cdcommand (cmdlet) within the shell's process. However,

    since PowerShell is based on the .NET Framework and has a different architecturethan previous shells, all of PowerShell's cmdlets like ls, rm etc. run in the shell'sprocess. Of course, this is not true for legacy commands which still run in a separateprocess.

    Interpreters other than an operating systems shell

    In the File Transfer Protocol, the respective command is spelled CWDin the controlstream,but is available as cdin most client command-line programs. Some clientsalso havethe lcdfor changing the working directory locally.

    The command also pertains to command-line interpreters of various applicationsoftware.

    See also

    Directory structurepushd and popdchrootList of command-line interpreters

    References

    1. ^Why does each drive have its own current directory?

    http://blogs.msdn.com/b/oldnewthing/archive/2010/10/11/10073890.aspxhttp://en.wikipedia.org/wiki/List_of_command-line_interpretershttp://en.wikipedia.org/wiki/Chroothttp://en.wikipedia.org/wiki/Pushd_and_popdhttp://en.wikipedia.org/wiki/Directory_structurehttp://en.wikipedia.org/wiki/Client_(computing)http://en.wikipedia.org/wiki/File_Transfer_Protocolhttp://en.wikipedia.org/wiki/Rm_(Unix)http://en.wikipedia.org/wiki/Lshttp://en.wikipedia.org/wiki/.NET_Frameworkhttp://en.wikipedia.org/wiki/Scripting_languagehttp://en.wikipedia.org/wiki/Windows_PowerShellhttp://en.wikipedia.org/wiki/Parent_processhttp://en.wikipedia.org/wiki/Child_processhttp://en.wikipedia.org/wiki/Process_(computing)http://en.wikipedia.org/wiki/Lshttp://en.wikipedia.org/wiki/C_(programming_language)http://en.wikipedia.org/wiki/POSIXhttp://en.wikipedia.org/wiki/Windows_APIhttp://en.wikipedia.org/wiki/COMMAND.COMhttp://en.wikipedia.org/wiki/Windows_PowerShellhttp://en.wikipedia.org/wiki/Cmd.exehttp://en.wikipedia.org/wiki/Bash_(Unix_shell)http://en.wikipedia.org/wiki/Tcshhttp://en.wikipedia.org/wiki/Bourne_shellhttp://en.wikipedia.org/wiki/Unix_shell
  • 8/12/2019 CD (Command)

    5/5

    (http://blogs.msdn.com/b/oldnewthing/archive/2010/10/11/10073890.aspx)2. ^Unix Change Directory Commands (http://unix-simple.blogspot.com/2006/12/unix-

    change-directory-commands.html)

    External links

    Windows XP > Command-line reference A-Z > Chdir (Cd)(http://technet.microsoft.com/en-us/library/bb490875.aspx) from MicrosoftTechNetcd(http://www.opengroup.org/onlinepubs/9699919799/utilities/cd.html) : change thworking directory Commands & Utilities Reference, The Single UNIXSpecification, Issue 7 from The Open Group

    Retrieved from "http://en.wikipedia.org/w/index.php?title=Cd_(command)&oldid=597089505"Categories: Windows commands Internal DOS commands File system directories

    OS/2 Windows administration Standard Unix programs Unix SUS2008 utilities

    Thispage was last modified on 25 February 2014 at 16:43.Text is available under the Creative Commons Attribution-ShareAlike License;additional terms may apply. By using this site, you agree to the Terms of Use anPrivacy Policy.Wikipedia is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.

    http://www.wikimediafoundation.org/http://wikimediafoundation.org/wiki/Privacy_policyhttp://wikimediafoundation.org/wiki/Terms_of_Usehttp://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_Licensehttp://en.wikipedia.org/wiki/Help:Categoryhttp://en.wikipedia.org/w/index.php?title=Cd_(command)&oldid=597089505http://en.wikipedia.org/wiki/The_Open_Grouphttp://en.wikipedia.org/wiki/Single_Unix_Specificationhttp://www.opengroup.org/onlinepubs/9699919799/utilities/cd.htmlhttp://en.wikipedia.org/wiki/Microsoft_TechNethttp://technet.microsoft.com/en-us/library/bb490875.aspxhttp://unix-simple.blogspot.com/2006/12/unix-change-directory-commands.htmlhttp://blogs.msdn.com/b/oldnewthing/archive/2010/10/11/10073890.aspxhttp://en.wikipedia.org/wiki/Category:Unix_SUS2008_utilitieshttp://en.wikipedia.org/wiki/Category:Standard_Unix_programshttp://en.wikipedia.org/wiki/Category:Windows_administrationhttp://en.wikipedia.org/wiki/Category:OS/2http://en.wikipedia.org/wiki/Category:File_system_directorieshttp://en.wikipedia.org/wiki/Category:Internal_DOS_commandshttp://en.wikipedia.org/wiki/Category:Windows_commands