Linux Basics · Lesson 6 · 15 min

Moving around: cd

Now that you can look around, it's time to walk around. cd means change directory, and it's the command you'll type more than any other.

You will learn

  • The Linux folder tree, and why there's no C:\
  • cd, cd .., cd ~, cd -
  • Absolute vs relative paths
  • Where important files live, including where Rocky and Ubuntu keep their logs

One big upside-down tree

Windows has separate drives like C:\ and D:\. Linux has one single tree that starts at /, called “root.” Everything lives somewhere under it: your files, settings, programs, even USB sticks.

/ ← the root of everything ├── etc ← settings files (“edit to configure”) ├── home ← users' personal folders │ └── student ← YOUR home, also called ~ │ ├── Documents │ └── games ├── root ← the admin's home (not the same as / !) ├── tmp ← temporary scratch space, cleared on reboot ├── usr │ └── bin ← programs like ls and cp live here └── var ├── log ← log files: the system's diary └── www ← websites (lesson 14)

This layout is almost identical on Rocky and Ubuntu. It follows a shared standard, so skills transfer between the two. Lesson 7 tours every one of these folders.

The cd moves

Same on both
cd Documents     # go into Documents (inside where I am)
cd ..            # go UP one level
cd ../..         # go up two levels
cd /etc          # go to an exact place, starting from the root
cd               # go home, from anywhere
cd ~             # also home
cd -             # go back to where I just was (like a Back button)

Absolute vs relative paths

A path is directions to a file or folder. There are two kinds:

Pro move

Type the first few letters and press Tab. cd Doc + Tab becomes cd Documents/. No typos, and if nothing completes, the thing you're typing probably doesn't exist. If a name has spaces, put quotes around it: cd "My Folder".

Where the logs live

Logs are the system's diary. When something breaks, admins go to /var/log first. This is one place where the families use different file names:

What's loggedRocky / RHELUbuntu / Debian
General system messages/var/log/messages/var/log/syslog
Logins, sudo, SSH/var/log/secure/var/log/auth.log
Software installs/var/log/dnf.log/var/log/apt/history.log
Everything (modern way)journalctl, the same on both

Try it: treasure hunt 🗺️

A treasure is hidden somewhere inside games/maze. Explore with cd and ls, and read any clues you find with cat.

Quick check

1. You're in /home/student/games/maze. Where does cd .. take you?

2. Which of these is an absolute path?

3. On Ubuntu you want to see who logged in over SSH. Which file?

Finished the missions and the quiz? Mark it done to track your progress.