cdchange working directory |
KornShell Built-in |
cd [directory]
cd old new
cd -
changes the working directory of the current KornShell execution environment (seecd directory
sh) to directory.
If directory is an absolute path name, beginning with /,
this is the target directory. If directory is a relative path name,
cd assumes it is relative to the current working directory.
In the KornShell, if the variable CDPATH is defined,
the built-in cd command searches for a relative path name under
each of the directories defined in CDPATH.
If cd finds the directory outside the current working
directory, it displays the new working directory.
Use colons to separate directories in CDPATH.
In CDPATH, a null string represents the current directory.
For example, if the value of CDPATH begins with a separator
character, cd searches the current directory first; if
it ends with a separator character, cd searches the current
directory last.
In the MKS KornShell, the command
is a special case that changes the working directory to the previous working directory by exchanging the values of the variablescd -
PWD and OLDPWD.
Repeating this command toggles the current working directory between the current and old working directory.
cd without arguments sets the working directory
to the value of the HOME environment variable, if the
variable exists. If there is no HOME variable,
cd does not change the current directory.
The form
is an extension to traditional KornShell implementations. The shell keeps the name of the current directory in the variablecd old new
PWD.
The cd command scans the current value of
PWD and replaces the first occurrence of the string
old with the string new.
The shell displays the resulting value of PWD and it
becomes the new working directory.
CDPATHcontains a list of directories for cd to search under when
directory is a relative path name.
HOMEcontains the name of your home directory. This is used when you do not specify directory on the command line.
OLDPWDcontains the path name of the previous working directory. This is used
by cd -.
PWDcontains the path name of the current working directory. This is set
by cd after changing to that directory.
0Successful completion.
1Failure due to any of the following:
HOME directory2An invalid command line option.
cd was unable to locate the target directory.
This does not change the working directory.
You are using the restricted version of the KornShell (for example, by
specifying the -r option for
sh). The restricted shell does
not allow the cd command.
You have not assigned a value to the HOME
environment variable. Thus when you say cd to return
to your home directory, cd cannot figure out what your
home directory is.
You tried the command cd - to
return to your previous directory, but there is no record of your previous
directory.
You tried a command of the form
However, the name of the current directory dir does not contain any string matching the regular expression old.cd old new
cd old new form of the command is
an extension to the POSIX standard.