The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


cd - change the working directory


cd [directory]

cd - 


The cd utility will change the working directory of the current shell execution environment; see Shell Execution Environment .  If the current working directory is successfully changed, it will save an absolute pathname of the old working directory in the environment variable OLDPWD and it will save an absolute pathname of the new working directory in the environment variable PWD .

When invoked with no operands, and the HOME environment variable is set to a non-empty value, the directory named in the HOME environment variable will become the new working directory. If HOME is empty or is undefined, the default behaviour is implementation-dependent.




The following operands are supported:
An absolute or relative pathname of the directory that becomes the new working directory. The interpretation of a relative pathname by cd depends on the CDPATH environment variable.
When a hyphen is used as the operand, this is equivalent to the command:

cd "$OLDPWD" && pwd 

which changes to the previous working directory and then writes its name.


Not used.




The following environment variables affect the execution of cd:
A colon-separated list of pathnames that refer to directories. If the directory operand does not begin with a slash (/) character, and the first component is not dot or dot-dot, cd will search for directory relative to each directory named in the CDPATH variable, in the order listed. The new working directory will be set to the first matching directory found. An empty string in place of a directory pathname represents the current directory. If CDPATH is not set, it will be treated as if it were an empty string.
The name of the home directory, used when no directory operand is specified.
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
If set to a non-empty string value, override the values of all the other internationalisation variables.
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
Determine the location of message catalogues for the processing of LC_MESSAGES .
A pathname of the previous working directory, used by cd -.
A pathname of the current working directory, set by cd after it has changed to that directory.




If a non-empty directory name from CDPATH is used,  or if cd - is used,  an absolute pathname of the new working directory will be written to the standard output as follows:

"%s\n", <new directory>

Otherwise, there will be no output.


Used only for diagnostic messages.






The following exit values are returned:
The directory was successfully changed.
An error occurred.


The working directory remains unchanged.


Since cd affects the current shell execution environment, it is always provided as a shell regular built-in. If it is called in a subshell or separate utility execution environment, such as one of the following:

(cd /tmp)
nohup cd
find . -exec cd {} \;

it will not affect the working directory of the caller's environment.

The user must have execute (search) permission in directory in order to change to it.






pwd, the XSH specification description of chdir().

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]