change directory
# Change directory
cd dir
# To user's home
cd ~
cd $HOME
# To last dir
cd -
cd $OLDPWD
cd [-L|[-P [-e]]] [dir]
- The variable HOME is the default dir.
- The variable CDPATH defines the search path for the directory containing dir.
- Alternative directory names in CDPATH are separated by a colon
:
. - A null directory name in CDPATH is the same as the current directory, i.e.,
.
.
- Alternative directory names in CDPATH are separated by a colon
- If dir begins with a slash (/), then CDPATH is not used.
- An argument of
-
is equivalent to$OLDPWD
. - If a non-empty directory name from CDPATH is used, or if
-
is the first argument, and the directory change is successful, the absolute pathname of the new working directory is written to the standard output. - The return value is true if the directory was successfully changed; false otherwise.
-P
Use the physical directory structure instead of following symbolic links- see also the -P option to the
set
builtin command
- see also the -P option to the
-L
Forces symbolic links to be followed-e
If the-e
option is supplied with-P
, and the current working directory cannot be successfully determined after a successful directory change,cd
will return an unsuccessful status.