12 September 2021

cd is a command used to change the shell working directory.
Using this command with some environment variables helps to navigate accross a system directories.
If directory is not supplied, the value of the HOME shell variable is used.

Note: all example below could be execute in a container:

docker run -it  ubuntu /bin/bash

Open a directory

$ cd etc

Open a directory using CDPATH

If the shell variable CDPATH exists, it is used as a search path: each directory name in CDPATH is searched for directory, with alternative directory names in CDPATH separated by a colon (‘:’).
This feature is usefull if you have some directories visited frequently.

$ export CDPATH='etc:media'
$ pwd
/
$ cd dpkg
/etc/dpkg

Go home

There some alternatives:

$ cd

or

$ cd ~

or

$ cd ${HOME}

Parent directory

$ cd ..

Previous directory

$ cd -

References