cd command (changes the current directory)
- Organization of this page
Format 1
cd [directory-path]
Format 2
cd old new
Description
This command changes the current directory. The destination can be specified in either of two formats.
The first format specifies the destination in directory-path. If the variable CDPATH is defined, this format specifies a directory relative to the location defined in CDPATH. If the variable CDPATH is not defined, this format specifies a directory relative to the current directory.
In the second format, the change is to the directory path in which the character string matching old is replaced with new in the path name of the current directory.
Arguments
- directory-path
-
Specifies the new directory path.
If this argument is omitted, the change is to the user's home directory (HOME variable). If a hyphen (-) is specified for this argument, the change is to the previous working directory (OLDPWD variable).
- old
-
Specifies a character string that is to be replaced in the path name of the current directory.
- new
-
Specifies the character string that is to replace the specified character string in the path name of the current directory.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 |
Error termination |
Notes
-
Executing the cd command in Windows converts the directory delimiter from / to \.
-
Even if the command syntax of this regular built-in command is invalid, it does not exit the shell that is executing the command.
-
If HOME is not defined, an error results if you execute the cd command with no argument specified.
-
A name in UNC format cannot be specified for the directory path name.
-
In Format 2, if a character string that occurs multiple times in the current directory path name is specified for substitution, only the first instance of that character string will become subject to substitution. An example follows.
Example: The current directory path name is /home/user/test/test
cd test tmp.
In this case, the cd command attempts to change the path to /home/user/tmp/test instead of /home/user/tmp/tmp.
Usage example
-
Change from /var/log to /var/lib.
Contents of the job definition script
pwd cd log lib p2w2d1222
Contents of the STDOUT file of the execution job
******** JOB SCOPE STDOUT ******** /var/log /var/lib /var/lib