Bash - Cd (Change Directory) builtin command



cd [-L|-P] [dir|-]


If a directory change is successful through CDPATH or -, 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.

Environment variable


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., ..

If dir begins with a slash (/), then CDPATH is not used.

A colon-separated list of search paths available to the cd command, similar in function to the $PATH variable for binaries. The $CDPATH variable may be set in the local ~/.bashrc file.

bash$ cd bash-doc
bash: cd: bash-doc: No such file or directory

bash$ CDPATH=/usr/share/doc
bash$ cd bash-doc

bash$ echo $PWD

Documentation / Reference

Powered by ComboStrap