SYNOPSIS
cd
[
cd
[
cd
[
DESCRIPTION
The command
cd directory
changes the working directory of the current KornShell execution environment (see sh) to directory. If directory is an absolute path name, beginning with \ (or / if you are working in the MKS KornShell), this is the target directory. If directory is a relative path name, cd assumes it is relative to the current working directory.
On Windows systems, the MKS KornShell maintains a current working directory for each drive. As a result, the command
cd x:directory
where x is a drive letter and directory is not an absolute path name, sets the working directory to directory relative to Drive x's current working directory. Directory is now Drive x's current working directory. If directory is an absolute path name, cd sets the working directory to directory relative to Drive x's root 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 semicolons 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
cd -
is a special case that changes the working directory to the previous working directory by exchanging the values of the variables PWD and OLDPWD.
- Note:
-
Repeating this command toggles the current working directory between the current and old working directory.
Calling 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
cd old new
is an extension to traditional KornShell implementations. The shell keeps the name of the current directory in the variable 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.
Options
-L -
retains symbolic links (if present in the specified destination directory) in the value assigned to the PWD environment variable, and as a result, in the directory name displayed for the new current directory.
- Note:
-
Symbolic links are only available on 8.1/2012R2/2016/2019/2022 systems with the NTFS file system.
-P -
replaces any symbolic links in the specified destination directory with actual physical link in the value assigned to PWD environment variable, and as a result, in the directory name displayed for the new current directory. Similar behavior can be achieved by setting set
-P or set-o physical .- Note:
-
Symbolic links are only available on 8.1/2012R2/2016/2019/2022 systems with the NTFS file system.
ENVIRONMENT VARIABLES
- CDPATH
-
contains a list of directories for cd to search under when directory is a relative path name.
- HOME
-
contains the name of your home directory. This is used when you do not specify directory on the command line.
- OLDPWD
-
contains the path name of the previous working directory. This is used by cd
- . - PWD
-
contains the path name of the current working directory. This is set by cd after changing to that directory.
DIAGNOSTICS
Possible exit status values are:
Messages
- "dir" bad directory
-
cd was unable to locate the target directory. This does not change the working directory.
- Restricted
-
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. - No HOME directory
-
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.
- No previous directory
-
You tried the command cd
- to return to your previous directory, but there is no record of your previous directory. - Pattern "old" not found in "dir"
-
You tried a command of the form
cd old new
However, the name of the current directory dir does not contain any string matching the regular expression old.
PORTABILITY
POSIX.2. x/OPEN Portability Guide 4.0. Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.
Unlike the command of the same name under Windows, the PTC MKS Toolkit cd can change the current disk as well as the current directory.
All UNIX systems feature the first form of the command.
In the PTC MKS Toolkit implementation of this command, all forms are built into the MKS KornShell.
The directory separator in CDPATH is a semicolon on Windows systems, but a colon on UNIX and POSIX-compliant systems.
The cd old new form of the command is an extension to the POSIX standard.
AVAILABILITY
PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC Windchill Requirements and Validation
SEE ALSO
PTC MKS Toolkit 10.4 Documentation Build 39.