Change the current directory.
cd [ -sLP ] [ arg ]
Changes the current directory. In the first form, change the current directory to arg, or to the value of $HOME if arg is not specified. If arg is -, change to the value of $OLDPWD, the previous directory. Otherwise, if a directory named arg is not found in the current directory and arg does not begin with a slash, search each component of the shell parameter cdpath. If no directory is found and the option CDABLE_VARS is set, and a parameter named arg exists whose value begins with a slash, treat its value as the directory. In that case, the parameter is added to the named directory hash table.
cd [ -sLP ] old new
Here the cd substitutes the string new for the string old in the name of the current directory, and tries to change to this new directory.
cd [ -sLP ] {+|-}n
cd extracts an entry from the directory stack, and changes to that directory.
Option | Description |
---|---|
+n |
A stack entry by counting from the left of the list shown by the dirs command, starting with zero. |
-n |
Counts from the right. If the PUSHD_MINUS option is set, the meanings of + and - in this context are swapped. |
-s |
cd refuses to change the current directory if the given pathname contains symlinks. |
-P or CHASE_LINKS |
Symbolic links are resolved to their true values. |
-L |
Symbolic links are followed regardless of the state of the CHASE_LINKS option. |