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

 NAME

cd - change the working directory

 SYNOPSIS



cd [directory]

cd - 

 DESCRIPTION

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.

 OPTIONS

None.

 OPERANDS

The following operands are supported:
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.
-
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.

 STDIN

Not used.

 INPUT FILES

None.

 ENVIRONMENT VARIABLES

The following environment variables affect the execution of cd:
CDPATH
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.
HOME
The name of the home directory, used when no directory operand is specified.
LANG
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.
LC_ALL
If set to a non-empty string value, override the values of all the other internationalisation variables.
LC_CTYPE
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).
LC_MESSAGES
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH
Determine the location of message catalogues for the processing of LC_MESSAGES .
OLDPWD
A pathname of the previous working directory, used by cd -.
PWD
A pathname of the current working directory, set by cd after it has changed to that directory.

 ASYNCHRONOUS EVENTS

Default.

 STDOUT

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.

 STDERR

Used only for diagnostic messages.

 OUTPUT FILES

None.

 EXTENDED DESCRIPTION

None.

 EXIT STATUS

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

 CONSEQUENCES OF ERRORS

The working directory remains unchanged.

 APPLICATION USAGE

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.

 EXAMPLES

None.

 FUTURE DIRECTIONS

None.

 SEE ALSO

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 ]