Back to course

16. Navigating the Filesystem: The `cd` Command

Linux Basics: From Zero to CLI Hero

Changing Location

The cd command (Change Directory) is used to move between directories in the filesystem.

Basic Moves

To move into a directory (using a relative path):

bash $ cd Documents $ pwd /home/user/Documents

To move into a directory using an absolute path:

bash $ cd /etc/network $ pwd /etc/network

Special cd Shortcuts

  1. Home Directory (~): The tilde (~) represents your user's home directory (/home/yourusername). bash $ cd ~

    Now you are back in /home/yourusername

  2. Parent Directory (..): Two dots represent the directory one level above the current one. bash $ cd ..

    If you were in /home/user/Documents, you are now in /home/user

  3. Root Directory (/): bash $ cd /

    Now you are at the very top of the filesystem hierarchy

  4. Previous Directory (-): A hyphen quickly returns you to the directory you were just in. bash $ cd -