Chdir

From Free net encyclopedia

Template:Lowercase

The chdir or cd command (change directory) in the Unix and DOS operating systems, is used to change the current working directory. It is available for use at the command line as well as in a Unix shell script or DOS batch file. cd is frequently included built into certain shells such as the Bourne shell, tcsh, bash, and COMMAND.COM.

A folder or directory is a logical section of a partition used to hold files. A directory is allowed to contain a directory. The CD command can be used to move down into a directory, move back into the parent directory, move all the way back to the root (/ in UNIX, \ in DOS) or move to any given directory name.

For example, in Unix:

  me@host:~$ ls
  workreports games encyclopedia text.txt
  me@host:~$ cd games
  me@host:games$ 

The user is now in the "games" directory.

Image:Chdir example.png

The same thing in DOS 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>


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.


chdir() is also a POSIX C function which changes the working directory.


CHDIR() is also a Visual Basic function which changes the working directory.es:Chdir nl:Cd (Unix) ru:Chdir fi:Chdir