CD(1) General Commands Manual CD(1)

cdchange working directory

cd [directory]

The cd utility shall change the working directory of the current shell execution environment; see 3.12. When invoked with no operands, and the HOME environment variable is set to a nonempty value, the directory named in the HOME environment variable shall become the new working directory. If HOME is empty or is undefined, the default behavior is implementation defined.

None.

The following operands shall be supported by the implementation:

directory

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. If directory is −, the results are implementation defined.

None.

None.

The following environment variables shall 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 shall search for directory relative to each directory named in the CDPATH variable, in the order listed. The new working directory shall 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 shall be treated as if it were an empty string.

The name of the home directory, used when no directory operand is specified.

This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_ ) do not specify a locale. See 2.6.

This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_.

This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments).

This variable shall determine the language in which messages should be written.

Default.

If a nonempty directory name from CDPATH is used, an absolute pathname of the new working directory shall be written to the standard output as follows: "%s\n", <new directory> Otherwise, there shall be no output.

Used only for diagnostic messages.

None.

None.

The cd utility shall exit with one of the following values:

The directory was successfully changed.

An error occurred.

The working directory remains unchanged.

Editor’s Note: A balloter requested that the following rationale be highlighted in the . 2 recirculation.

Since cd affects the current shell execution environment, it is generally 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 use of the CDPATH was introduced in the System V shell. Its use is analogous to the use of the variable in the shell. Earlier systems such as the C-shell used a shell parameter cdpath for this purpose.

A common extension when HOME is undefined is to get the login directory from the user database for the invoking user. This does not occur on System V implementations. Not included in this description are the features from the KornShell such as setting , toggling current and previous directory ( cd −), and the twooperand form of cd ( cd old new). This standard does not specify the results of cd

  • or of calls with more than one operand. Since these extensions are mostly used

in interactive situations, they may be considered for inclusion in POSIX. 2a. The result of cd - and of using no arguments with HOME unset or null have been made implementation defined at the request of the POSIX. 6 security working group. The setting of the variable was removed from earlier drafts, as it can be replaced by $(pwd).

September 1991 posix.fail