Main Page | See live article | Alphabetical index

Cd (DOS / Unix Command)

The 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 command file.

A 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 up into a directory, move back into the parent directory, move all the way back to the root (/ in unix, C:\\ in dos) or move to any given directory name.

For example, in unix:

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

The user is now in the "Games" directory.

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

cd is a command which is frequently included built into certain shellss such as the Bourne shell, tcsh, and bash. It can be implemented easily with the POSIX C function chdir().