← Operating System Basics: From Zero to Hero
Level 2 · Explorer: Inside Linux

Drivers and Devices: Everything Is a File

Lesson 11 of 14 · ⏱ 12 min

Computers use thousands of different devices: mice, keyboards, printers, screens, cameras. Every maker builds them differently. How does one OS manage them all? With drivers, and with a beautiful Linux idea: "everything is a file." 🧩

A driver is a translator

A driver is a small program that knows how to talk to one kind of device. The OS speaks one language, the device speaks its own, and the driver translates.

Six steps: you press A, the keyboard sends a signal, the driver translates it, the OS decides who gets it, the app receives it, and the screen shows it.

On Linux, most drivers are kernel modules: little pieces the kernel can load when it needs them.

🧪 Lab 1: meet the kernel's modules

lsmod | head -10

lsmod lists the loaded modules (drivers). The first column is the module's name and the second is how much memory it uses. Count them:

lsmod | wc -l

Every one is a translator the kernel loaded for a part of your computer!

🧪 Lab 2: devices are files

ls /dev | head -20

Each name is a device. You'll find special ones. Let's play with three of them:

echo "this vanishes" > /dev/null

/dev/null is a black hole. Anything sent there disappears, which is handy for hiding output.

head -c 8 /dev/zero | od -An -tx1

/dev/zero gives endless zero bytes. od shows them as numbers: you'll see 00 00 00 00 00 00 00 00.

head -c 8 /dev/urandom | od -An -tx1
head -c 8 /dev/urandom | od -An -tx1

/dev/urandom gives random bytes from the OS. Run it twice: the numbers are different each time! Computers use this for secrets like passwords.

🧪 Lab 3: watch the keyboard talk

Type this, then press Enter:

cat

Now type some letters and press Enter after each line. Each time the screen shows your line again. The keyboard driver sent your keys to the OS, the OS gave them to cat, and cat handed them to the screen driver. That's the key press journey from the picture! Press Ctrl + D (or Ctrl + C) to stop.

🧪 Lab 4: interrupts: a tap on the shoulder

How does the CPU know you pressed a key? It doesn't keep asking "Did you press anything?" That would waste time. Instead, the device sends an interrupt, a tap on the CPU's shoulder saying "Excuse me, I need attention!"

head -12 /proc/interrupts

Each row is a device or part of the computer, and the numbers show how many interrupts it has sent to each CPU core. Run it again after typing a little, and watch some numbers grow!

🧪 Lab 5: meet the USB devices (with a grown-up)

lsusb

This lists the USB devices attached. If your computer has USB ports, plug in a mouse or a keyboard and run the command again. A new line appears! Unplug it and run it once more: it's gone. (If lsusb says "command not found", a grown-up can install it. It's in the usbutils package.)

For an even cooler view, watch devices arrive live:

udevadm monitor

Plug something in: events scroll by as the OS discovers the device and loads its driver. Press Ctrl + C to stop.

Plug and play

Most devices work the moment you plug them in, because the OS already has a driver for them. Sometimes, for fancy devices like a new printer or a graphics card, you install an extra driver.

🔌 Fun fact: Many Linux drivers are built into the kernel, written by thousands of people around the world.

Words to know

Word What it means
Driver A translator program between the OS and a device
Kernel module A driver the kernel can load when needed
Interrupt A device's tap on the CPU's shoulder
/dev/null A black hole file: whatever you send there disappears

🎯 Quiz time!

1. What does a driver do?
2. What happens to text you send to /dev/null?
3. What is an interrupt?
4. Which command lists the drivers (modules) the kernel has loaded?