Bash - Cd (Change Directory) builtin command

> Procedural Languages > Bash Shell and (Unix|Linux) Utilities (XCU) > Bash - File System

1 - About

Cd is a builtin command that changes the current directory

Advertising

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

4 - Environment variable

4.1 - HOME

The variable HOME is the default dir.

4.2 - 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    	      
Advertising

5 - Documentation / Reference

lang/bash/fs/cd.txt · Last modified: 2018/09/16 12:42 by gerardnico