Table of Contents

Bash - Cd (Change Directory) builtin command

About

File - Change Directory (cd) in bash. Cd is a builtin command that changes the current directory

Syntax

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

where:

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

HOME

The variable HOME is the default dir.

CDPATH

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
/usr/share/doc/bash-doc


bash$ echo $PWD
/usr/share/doc/bash-doc    	      

Documentation / Reference