About
File - Change Directory (cd) in bash. Cd is a builtin command that changes the current directory
Articles Related
Syntax
cd [-L|-P] [dir|-]
where:
- the options
- -L forces symbolic links to be followed.
- -P says to use the physical directory structure instead of following symbolic links (see also the -P option to the set builtin command);
- the arguments:
- dir is the target directory. Default to HOME. If dir begins with a slash (/), then cdpath is not used.
- - is equivalent to OLDPWD, the last current directory.
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