Information about Chdir

cd, sometimes also available as chdir (change directory), is a command line command to change the current working directory in operating systems such as Unix, Windows and DOS. It is also available for use in Unix shell scripts and in batch files on Windows or DOS. CHDIR() is also a Visual Basic function which changes the working directory.

Usage

A directory is a logical section of a filesystem 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 (/ in UNIX, \ in DOS) 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:

me@host:~$ ls workreports games encyclopedia text.txt me@host:~$ cd games me@host:~/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:\> dir workreports Wed Oct 9th 9:01 games Tue Oct 8th 14:32 encyclopedia Mon Oct 1st 10:05 text txt 1903 Thu Oct10th 12:43 C:\> cd games C:\games>

Note that cd has different effects on different operating systems if given with no arguments. For example, if executed without arguments in DOS, the current working directory is printed. If executed without arguments in Unix, then the user is returned to the home directory. The effect of executing the cd command within a script or batch file also varies. 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.

How it works

cd is frequently included built directly into the command line interpreter. This is the case in most of the Unix shells (Bourne shell, tcsh, bash, etc.), cmd.exe and Windows PowerShell on Windows and COMMAND.COM on DOS.

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 new 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.

References

See also

command line interface or CLI is a method of interacting with an operating system or software using a command line interpreter. This command line interpreter may be a text terminal, terminal emulator, or remote shell client such as PuTTY.
..... Click the link for more information.
In computing, the working directory of a process is the directory of a hierarchical file system, if any,[1] which is implicitly used to determine the file referenced to by the process with a file name only, or with a relative path (as opposed to files referenced by full
..... Click the link for more information.
An operating system (OS) is the software that manages the sharing of the resources of a computer. An operating system processes system data and user input, and responds by allocating and managing tasks and internal system resources as a service to users and programs of the
..... Click the link for more information.
Unix (officially trademarked as UNIX®) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy.
..... Click the link for more information.
Microsoft Windows

Screenshot of Windows Vista Ultimate, the latest version of Microsoft Windows.
Company/developer: Microsoft Corporation
OS family: MS-DOS/9x-based, Windows CE, Windows NT
Source model: Closed source

..... Click the link for more information.
DOS (from Disk Operating System) commonly refers to the family of closely related operating systems which dominated the IBM PC compatible market between 1981 and 1995 (or until about 2000, if Windows 9x systems are included): DR-DOS, FreeDOS, MS-DOS, Novell-DOS, OpenDOS, PC-DOS,
..... Click the link for more information.
A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.
..... Click the link for more information.
Microsoft Batch File

File extension: .bat .cmd .btm
Type of format: Scripting In MS-DOS, OS/2, and Windows, a batch file is a text file containing a series of commands intended to be executed by the command interpreter.
..... Click the link for more information.
Visual Basic

Paradigm: Event-driven
Developer: Microsoft
Typing discipline: Static, strong
Influenced by: QuickBASIC
Influenced: Visual Basic .NET
OS: Microsoft Windows

Visual Basic (VB
..... Click the link for more information.
In computing, a directory, catalog, or folder[1] is an entity in a file system which contains a group of files and/or other directories. A typical file system may contain thousands (or even hundreds of thousands) of directories.
..... Click the link for more information.
file system (often also written as filesystem) is a method for storing and organizing computer files and the data they contain to make it easy to find and access them.
..... Click the link for more information.
LS may refer to:
  • Lightspeed Media Corporation, a collection of nude teen websites
  • .ls, the Internet top-level domain for Lesotho
  • ls is a command specified by POSIX and the Single UNIX Specification. It lists files.
  • Jet2.

..... Click the link for more information.
In computing, dir is a command used for file and directory listing, specifically in CP/M and the command line interface (CLI) of the DOS operating system. It is analogous to the Unix ls command.
..... Click the link for more information.
In computing, the working directory of a process is the directory of a hierarchical file system, if any,[1] which is implicitly used to determine the file referenced to by the process with a file name only, or with a relative path (as opposed to files referenced by full
..... Click the link for more information.
command line interpreter (also command line shell, command language interpreter) is a computer program that reads lines of text entered by a user and interprets them in the context of a given operating system or programming language.
..... Click the link for more information.
Unix shell, also called "the command line", provides the traditional user interface for the Unix operating system and for Unix-like systems. Users direct the operation of the computer by entering command input as text for a shell to execute.
..... Click the link for more information.
The Bourne shell, or sh, was the default Unix shell of Unix Version 7, and replaced the Thompson shell, whose executable file had the same name, sh. It was developed by Stephen Bourne, of AT&T Bell Laboratories, and was released in 1977 in the Version 7 Unix release
..... Click the link for more information.
tcsh (pronounced "TC-Shell" or "T-shell") is a Unix shell based on and compatible with the C shell (csh). It is essentially the C shell with (programmable) filename completion, command-line editing, and a few other features.
..... Click the link for more information.
Bash is a Unix shell written for the GNU Project. The name of the actual executable is bash. Its name is an acronym for Bourne-again shell, a pun on the name of the Bourne shell (sh) (i.e.
..... Click the link for more information.
cmd.exe is the command line interpreter on OS/2, Windows CE and on Windows NT-based systems (including Windows 2000, XP, Vista, and Server 2003). It is the analog of COMMAND.COM in MS-DOS and Windows 9x systems, or of the shells used on Unix systems.
..... Click the link for more information.
Windows PowerShell, previously Microsoft Shell or MSH (codenamed Monad) is an extensible command line interface (CLI) shell and scripting language product developed by Microsoft. The product is based on object-oriented programming and version 2.
..... Click the link for more information.
COMMAND.COM is the filename of the default operating system shell (or command line interpreter) for DOS and 16/32bits versions of Windows (95/98/98 SE/Me). It also has an additional role, as the first program run after boot, hence being responsible for setting up the system by
..... Click the link for more information.
The Windows API, informally WinAPI, is the name given by Microsoft to the core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems.
..... Click the link for more information.
POSIX (IPA: /ˈpɒsɪks/) or "Portable Operating System Interface" [1] is the collective name of a family of related standards specified by the IEEE to define the application programming interface (API) for
..... Click the link for more information.
C

The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language.
..... Click the link for more information.
LS may refer to:
  • Lightspeed Media Corporation, a collection of nude teen websites
  • .ls, the Internet top-level domain for Lesotho
  • ls is a command specified by POSIX and the Single UNIX Specification. It lists files.
  • Jet2.

..... Click the link for more information.
Process (lat. processus - movement) is a naturally occurring or designed sequence of changes of properties or attributes of an object or system[1][2][3][4][5][6][7].
..... Click the link for more information.
A child process is a computer process created by another process (the parent process).

A child process inherits most of its attributes, such as open files, from its parent. In UNIX, a child process is in fact created (using fork) as a copy of the parent.
..... Click the link for more information.
A parent process is a computer process that has created one or more child processes.

In UNIX, every process except process 0 (the swapper) is created when another process executes the fork system call.
..... Click the link for more information.
Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs. It is based on several techniques, including inheritance, modularity, polymorphism, and encapsulation.
..... Click the link for more information.


This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus


page counter