cd — change directory — is how the shell moves. It has no output when it works, which is exactly why it is worth learning properly: the three or four special forms cover almost every navigation need.

Absolute and relative paths #

Move with absolute and relative paths
$ cd /var/log          # absolute: from the root
$ cd nginx             # relative: one level down
$ cd ..                # one level up
$ cd ../..             # two levels up

An absolute path starts with / and works from anywhere. A relative path starts from where you are now, which is why pwd is a useful habit before a tricky relative jump.

The shortcuts that matter #

FormMeaning
cd ~ or cdGo to your home directory
cd -Jump to the previous directory, like a back button
cd ..Up one level
cd ../siblingUp one, then into a neighbouring directory

cd - deserves a special mention. It swaps between the last two directories you were in, which is perfect when bouncing between a config directory and a project:

Bounce between two directories
$ cd /etc/nginx
$ cd ~/projects/aospix
$ cd -
/etc/nginx
$ cd -
/home/ana/projects/aospix

Paths with spaces #

Quote anything with spaces, or the shell will split it into two arguments:

Enter a directory whose name has spaces
$ cd "Virtual Machines"

Tab completion does the typing #

Type the first letters and press Tab. The shell completes the name, or shows options if several match. This is not a luxury — it is how you avoid typos on long paths, and it is the difference between cd feeling fragile and feeling instant.

Once you arrive, ls shows what is there, and mkdir is how you make a destination that does not exist yet. More from the terminal notes series lands every week.