CodeTheRobot

Ubuntu Linux for Robotics · Lesson 03 of 96

The Linux filesystem: /home, /etc, /usr, /opt, /var and /dev

One tree, no drive letters, and what each top-level folder is for.

Estimated time · 30–45 min

Learning goals

What you will understand

  • Explain the linux filesystem: /home, /etc, /usr, /opt, /var and /dev in your own words
  • Use it in a small workstation example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

Linux has one filesystem tree that starts at / (root). There are no drive letters: other disks are mounted onto folders. /home holds users' files, /etc system configuration, /usr installed programs and libraries, /opt optional or third-party software (ROS 2 lives in /opt/ros), /var changing data such as logs, and /dev device files for hardware.

Your home directory is written ~ (for example /home/robot). Hidden files begin with a dot (.bashrc). Everything is a file: a serial port is /dev/ttyUSB0, a camera is /dev/video0. Knowing where things live tells you where to look when something breaks.

Guided lesson

Work through these steps

  1. 1.

    Open a terminal and record the current state before changing anything.

  2. 2.

    Read the the linux filesystem: /home, /etc, /usr, /opt, /var and /dev commands and predict what each one does.

  3. 3.

    Run the commands one at a time and compare each output with your prediction.

  4. 4.

    Write the commands that worked in a setup note you can repeat later.

Worked example

Read it before you run it

ls /
# List the top-level folders.
ls /opt
# Third-party software such as ROS 2 is installed here.
ls /etc | head
# Configuration files for the system.
ls /var/log | head
# Log files (system, packages, services).
ls /dev | head
# Device files that represent hardware.
echo $HOME
# Print your home directory.

What the example is doing

  1. 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
  2. 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
  3. 3.Comments beginning with # explain safety checks and are not executed by the shell.

Watch it run · The robot's computer

See what this code does

The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.

robot computercpumemdiskdriverstoppedplannerstoppedloggerstoppedsafetystoppedTHE ROBOT'S COMPUTER

Demo for The Linux filesystem: /home, /etc, /usr, /opt, /var and /dev. Expected result: /dev /etc /home /opt /usr /var

Practice code

Now type it yourself

Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.

# List six standard folders on one line
# TODO: list only the folders /home /etc /usr /opt /var /dev (ls -d), and join the lines into one line with paste -sd' '

Expected output

/dev /etc /home /opt /usr /var
Stuck? Show the full solution (try it yourself first)
# List six standard folders on one line
ls -d /home /etc /usr /opt /var /dev | paste -sd' '

Expected result

How you know it worked

  • Each command completes without an unexplained error.
  • Your notes contain the command, the important output, and what it proves.

Practical exercise

Apply the lesson

Draw the top of the tree from memory, write one sentence for each of /home, /etc, /usr, /opt, /var and /dev, then find where ROS 2, a system log and your serial port appear.

Before you continue

  • You recorded the starting state
  • Every command and output is understood
  • The change can be repeated from your notes

If something goes wrong

A command says permission denied.

Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.

A command or package is not found.

Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.