{"id":5687,"date":"2022-12-20T18:57:26","date_gmt":"2022-12-20T21:57:26","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/cd-man1p\/"},"modified":"2022-12-20T18:57:26","modified_gmt":"2022-12-20T21:57:26","slug":"cd-man1p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/cd-man1p\/","title":{"rendered":"CD (man1p)"},"content":{"rendered":"<h1 align=\"center\">CD<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#OPTIONS\">OPTIONS<\/a><br \/> <a href=\"#OPERANDS\">OPERANDS<\/a><br \/> <a href=\"#STDIN\">STDIN<\/a><br \/> <a href=\"#INPUT FILES\">INPUT FILES<\/a><br \/> <a href=\"#ENVIRONMENT VARIABLES\">ENVIRONMENT VARIABLES<\/a><br \/> <a href=\"#ASYNCHRONOUS EVENTS\">ASYNCHRONOUS EVENTS<\/a><br \/> <a href=\"#STDOUT\">STDOUT<\/a><br \/> <a href=\"#STDERR\">STDERR<\/a><br \/> <a href=\"#OUTPUT FILES\">OUTPUT FILES<\/a><br \/> <a href=\"#EXTENDED DESCRIPTION\">EXTENDED DESCRIPTION<\/a><br \/> <a href=\"#EXIT STATUS\">EXIT STATUS<\/a><br \/> <a href=\"#CONSEQUENCES OF ERRORS\">CONSEQUENCES OF ERRORS<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">cd \u2014 change the working directory<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">cd <b>[<\/b>-L|-P<b>] [<\/b><i>directory<\/i><b>]<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">cd &#8211;<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>cd<\/i> utility shall change the working directory of the current shell execution environment (see <i>Section 2.12<\/i>, <i>Shell Execution Environment<\/i>) by executing the following steps in sequence. (In the following steps, the symbol <b>curpath<\/b> represents an intermediate value used to simplify the description of the algorithm used by <i>cd<\/i>. There is no requirement that <b>curpath<\/b> be made visible to the application.)<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>1.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>If no <i>directory<\/i> operand is given and the <i>HOME<\/i> environment variable is empty or undefined, the default behavior is implementation-defined and no further steps shall be taken.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>2.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>If no <i>directory<\/i> operand is given and the <i>HOME<\/i> environment variable is set to a non-empty value, the <i>cd<\/i> utility shall behave as if the directory named in the <i>HOME<\/i> environment variable was specified as the <i>directory<\/i> operand.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>3.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>If the <i>directory<\/i> operand begins with a <slash> character, set <b>curpath<\/b> to the operand and proceed to step 7.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>4.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>If the first component of the <i>directory<\/i> operand is dot or dot-dot, proceed to step 6.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>5.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>Starting with the first pathname in the <colon>-separated pathnames of <i>CDPATH<\/i> (see the ENVIRONMENT VARIABLES section) if the pathname is non-null, test if the concatenation of that pathname, a <slash> character if that pathname did not end with a <slash> character, and the <i>directory<\/i> operand names a directory. If the pathname is null, test if the concatenation of dot, a <slash> character, and the operand names a directory. In either case, if the resulting string names an existing directory, set <b>curpath<\/b> to that string and proceed to step 7. Otherwise, repeat this step with the next pathname in <i>CDPATH<\/i> until all pathnames have been tested.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>6.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>Set <b>curpath<\/b> to the <i>directory<\/i> operand.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>7.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>If the <b>\u2212P<\/b> option is in effect, proceed to step 10. If <b>curpath<\/b> does not begin with a <slash> character, set <b>curpath<\/b> to the string formed by the concatenation of the value of <i>PWD<\/i>, a <slash> character if the value of <i>PWD<\/i> did not end with a <slash> character, and <b>curpath<\/b>.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>8.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>The <b>curpath<\/b> value shall then be converted to canonical form as follows, considering each component from beginning to end, in sequence:<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\">a.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"18%\"><\/td>\n<td width=\"4%\"><\/td>\n<td width=\"1%\"><\/td>\n<td width=\"77%\">\n<p style=\"margin-top: 1em\">Dot components and any <slash> characters that separate them from the next component shall be deleted.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"18%\"><\/td>\n<td width=\"4%\">\n<p>b.<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"77%\">\n<p>For each dot-dot component, if there is a preceding component and it is neither root nor dot-dot, then:<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:23%;\">i.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"18%\"><\/td>\n<td width=\"10%\"><\/td>\n<td width=\"3%\"><\/td>\n<td width=\"69%\">\n<p style=\"margin-top: 1em\">If the preceding component does not refer (in the context of pathname resolution with symbolic links followed) to a directory, then the <i>cd<\/i> utility shall display an appropriate error message and no further steps shall be taken.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"18%\"><\/td>\n<td width=\"10%\">\n<p>ii.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"69%\">\n<p>The preceding component, all <slash> characters separating the preceding component from dot-dot, dot-dot, and all <slash> characters separating dot-dot from the following component (if any) shall be deleted.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"18%\"><\/td>\n<td width=\"10%\">\n<p>c.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"69%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:23%; margin-top: 1em\">An implementation may further simplify <b>curpath<\/b> by removing any trailing <slash> characters that are not also leading <slash> characters, replacing multiple non-leading consecutive <slash> characters with a single <slash>, and replacing three or more leading <slash> characters with a single <slash>. If, as a result of this canonicalization, the <b>curpath<\/b> variable is null, no further steps shall be taken.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"4%\">\n<p style=\"margin-top: 1em\">9.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p style=\"margin-top: 1em\">If <b>curpath<\/b> is longer than {PATH_MAX} bytes (including the terminating null) and the <i>directory<\/i> operand was not longer than {PATH_MAX} bytes (including the terminating null), then <b>curpath<\/b> shall be converted from an absolute pathname to an equivalent relative pathname if possible. This conversion shall always be considered possible if the value of <i>PWD<\/i>, with a trailing <slash> added if it does not already have one, is an initial substring of <b>curpath<\/b>. Whether or not it is considered possible under other circumstances is unspecified. Implementations may also apply this conversion if <b>curpath<\/b> is not longer than {PATH_MAX} bytes or the <i>directory<\/i> operand was longer than {PATH_MAX} bytes.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"4%\">\n<p>10.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>The <i>cd<\/i> utility shall then perform actions equivalent to the <i>chdir<\/i>() function called with <b>curpath<\/b> as the <i>path<\/i> argument. If these actions fail for any reason, the <i>cd<\/i> utility shall display an appropriate error message and the remainder of this step shall not be executed. If the <b>\u2212P<\/b> option is not in effect, the <i>PWD<\/i> environment variable shall be set to the value that <b>curpath<\/b> had on entry to step 9 (i.e., before conversion to a relative pathname). If the <b>\u2212P<\/b> option is in effect, the <i>PWD<\/i> environment variable shall be set to the string that would be output by <i>pwd<\/i> <b>\u2212P<\/b>. If there is insufficient permission on the new directory, or on any parent of that directory, to determine the current working directory, the value of the <i>PWD<\/i> environment variable is unspecified.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">If, during the execution of the above steps, the <i>PWD<\/i> environment variable is set, the <i>OLDPWD<\/i> environment variable shall also be set to the value of the old working directory (that is the current working directory immediately prior to the call to <i>cd<\/i>).<\/p>\n<h2>OPTIONS <a name=\"OPTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>cd<\/i> utility shall conform to the Base Definitions volume of POSIX.1-2017, <i>Section 12.2<\/i>, <i>Utility Syntax Guidelines<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The following options shall be supported by the implementation:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><b>\u2212L<\/b><\/p>\n<\/td>\n<td width=\"12%\"><\/td>\n<td width=\"74%\">\n<p style=\"margin-top: 1em\">Handle the operand dot-dot logically; symbolic link components shall not be resolved before dot-dot components are processed (see steps 8. and 9. in the DESCRIPTION).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p><b>\u2212P<\/b><\/p>\n<\/td>\n<td width=\"12%\"><\/td>\n<td width=\"74%\">\n<p>Handle the operand dot-dot physically; symbolic link components shall be resolved before dot-dot components are processed (see step 7. in the DESCRIPTION).<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">If both <b>\u2212L<\/b> and <b>\u2212P<\/b> options are specified, the last of these options shall be used and all others ignored. If neither <b>\u2212L<\/b> nor <b>\u2212P<\/b> is specified, the operand shall be handled dot-dot logically; see the DESCRIPTION.<\/p>\n<h2>OPERANDS <a name=\"OPERANDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following operands shall be supported:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"14%\">\n<p style=\"margin-top: 1em\"><i>directory<\/i><\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"74%\">\n<p style=\"margin-top: 1em\">An absolute or relative pathname of the directory that shall become the new working directory. The interpretation of a relative pathname by <i>cd<\/i> depends on the <b>\u2212L<\/b> option and the <i>CDPATH<\/i> and <i>PWD<\/i> environment variables. If <i>directory<\/i> is an empty string, the results are unspecified.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"14%\">\n<p>\u2212<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"74%\">\n<p>When a <hyphen-minus> is used as the operand, this shall be equivalent to the command:<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:32%; margin-top: 1em\">cd &#8220;$OLDPWD&#8221; &#038;&#038; pwd<\/p>\n<p style=\"margin-left:26%; margin-top: 1em\">which changes to the previous working directory and then writes its name.<\/p>\n<h2>STDIN <a name=\"STDIN\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Not used.<\/p>\n<h2>INPUT FILES <a name=\"INPUT FILES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>ENVIRONMENT VARIABLES <a name=\"ENVIRONMENT VARIABLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following environment variables shall affect the execution of <i>cd<\/i>:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p style=\"margin-top: 1em\"><i>CDPATH<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p style=\"margin-top: 1em\">A <colon>-separated list of pathnames that refer to directories. The <i>cd<\/i> utility shall use this list in its attempt to change the directory, as described in the DESCRIPTION. An empty string in place of a directory pathname represents the current directory. If <i>CDPATH<\/i> is not set, it shall be treated as if it were an empty string.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><i>HOME<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>The name of the directory, used when no <i>directory<\/i> operand is specified.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><i>LANG<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1-2017, <i>Section 8.2<\/i>, <i>Internationalization Variables<\/i> for the precedence of internationalization variables used to determine the values of locale categories.)<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><i>LC_ALL<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>If set to a non-empty string value, override the values of all the other internationalization variables.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><i>LC_CTYPE<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><i>LC_MESSAGES<\/i><\/p>\n<p style=\"margin-left:26%;\">Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><i>NLSPATH<\/i><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>Determine the location of message catalogs for the processing of <i>LC_MESSAGES<\/i>.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><i>OLDPWD<\/i><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>A pathname of the previous working directory, used by <i>cd<\/i> <b>\u2212<\/b>.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><i>PWD<\/i><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>This variable shall be set as specified in the DESCRIPTION. If an application sets or unsets the value of <i>PWD<\/i>, the behavior of <i>cd<\/i> is unspecified.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>ASYNCHRONOUS EVENTS <a name=\"ASYNCHRONOUS EVENTS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Default.<\/p>\n<h2>STDOUT <a name=\"STDOUT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">If a non-empty directory name from <i>CDPATH<\/i> is used, or if <i>cd<\/i> <b>\u2212<\/b> is used, an absolute pathname of the new working directory shall be written to the standard output as follows:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">&#8220;%sn&#8221;, <<i>new directory<\/i>><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Otherwise, there shall be no output.<\/p>\n<h2>STDERR <a name=\"STDERR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The standard error shall be used only for diagnostic messages.<\/p>\n<h2>OUTPUT FILES <a name=\"OUTPUT FILES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>EXTENDED DESCRIPTION <a name=\"EXTENDED DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>EXIT STATUS <a name=\"EXIT STATUS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following exit values shall be returned:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\">0<\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"60%\">\n<p style=\"margin-top: 1em\">The directory was successfully changed.<\/p>\n<\/td>\n<td width=\"20%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p>>0<\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"60%\">\n<p>An error occurred.<\/p>\n<\/td>\n<td width=\"20%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>CONSEQUENCES OF ERRORS <a name=\"CONSEQUENCES OF ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The working directory shall remain unchanged.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Since <i>cd<\/i> 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:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">(cd \/tmp) <br \/> nohup cd <br \/> find . -exec cd {} ;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">it does not affect the working directory of the caller\u2019s environment.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The user must have execute (search) permission in <i>directory<\/i> in order to change to it.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following template can be used to perform processing in the directory specified by <i>location<\/i> and end up in the current working directory in use before the first <i>cd<\/i> command was issued:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">cd <i>location<\/i> <br \/> if [ $? -ne 0 ] <br \/> then <br \/> print error message <br \/> exit 1 <br \/> fi <br \/> &#8230; do whatever is desired as long as the OLDPWD environment variable <br \/> is not modified <br \/> cd &#8211;<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The use of the <i>CDPATH<\/i> was introduced in the System V shell. Its use is analogous to the use of the <i>PATH<\/i> variable in the shell. The BSD C shell used a shell parameter <i>cdpath<\/i> for this purpose.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">A common extension when <i>HOME<\/i> is undefined is to get the login directory from the user database for the invoking user. This does not occur on System V implementations.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Some historical shells, such as the KornShell, took special actions when the directory name contained a dot-dot component, selecting the logical parent of the directory, rather than the actual parent directory; that is, it moved up one level toward the <b>\u2019\/\u2019<\/b> in the pathname, remembering what the user typed, rather than performing the equivalent of:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">chdir(&#8220;..&#8221;);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In such a shell, the following commands would not necessarily produce equivalent output for all directories:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">cd .. &#038;&#038; ls ls ..<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This behavior is now the default. It is not consistent with the definition of dot-dot in most historical practice; that is, while this behavior has been optionally available in the KornShell, other shells have historically not supported this functionality. The logical pathname is stored in the <i>PWD<\/i> environment variable when the <i>cd<\/i> utility completes and this value is used to construct the next directory name if <i>cd<\/i> is invoked with the <b>\u2212L<\/b> option.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>Section 2.12<\/i>, <i>Shell Execution Environment<\/i>, <i>pwd<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <i>Chapter 8<\/i>, <i>Environment Variables<\/i>, <i>Section 12.2<\/i>, <i>Utility Syntax Guidelines<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The System Interfaces volume of POSIX.1-2017, <i>chdir<\/i>()<\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http:\/\/www.opengroup.org\/unix\/online.html .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https:\/\/www.kernel.org\/doc\/man-pages\/reporting_bugs.html .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  cd \u2014 change the working directory <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3782,1],"tags":[2516,2511],"class_list":["post-5687","post","type-post","status-publish","format-standard","hentry","category-1p-posix-comandos-generales","category-sin-categoria","tag-cd","tag-man1p"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=5687"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5687\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}