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
cddepends on the CDPATH environment variable. - -
- When a hyphen is used as the operand, this is equivalent to the command:
which changes to the previous working directory and then writes its name.
cd "$OLDPWD" && pwd
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,
cdwill search for directory relative to each directory named in theCDPATHvariable, 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. IfCDPATHis 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
LANGis 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
cdafter 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:
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 {} \;
The user must have execute (search) permission in directory in order to change to it.
EXAMPLES
None.
FUTURE DIRECTIONS
None.