Skip to main content

💾 Lesson 6.2: Disk and System Information

Know thy machine — how much disk space is left, how much RAM is available, and what hardware you're running on.

🎯 Learning Objectives

  • Check disk usage and free space with df and du
  • Monitor memory usage with free
  • Inspect CPU and hardware with lscpu, lsblk, and lshw
  • View system and kernel info with uname and hostnamectl
  • Check system uptime and logs

Estimated Time: 35 minutes

📑 In This Lesson

Disk Free Space (df)

df (disk free) shows how much space is used and available on each mounted filesystem.

# Human-readable format (GB, MB)
df -h

# Show only specific filesystem types (exclude virtual ones)
df -h -x tmpfs -x devtmpfs -x squashfs

# Show info for a specific path
df -h /home

# Show filesystem types
df -hT

Example Output

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       234G  45G   177G  21% /
/dev/sda1       512M   6M   506M   2% /boot/efi
/dev/sdb1       932G  120G  812G  13% /home
ColumnMeaning
FilesystemThe device or partition
SizeTotal capacity
UsedSpace currently occupied
AvailSpace remaining
Use%Percentage full
Mounted onWhere this filesystem is accessible

⚠️ Watch the Percentage

When a filesystem hits 100%, bad things happen — programs can't write files, logs stop, and the system may become unstable. Keep an eye on Use% and investigate if anything goes above 85%.

Disk Usage (du)

While df shows overall filesystem usage, du (disk usage) shows how much space specific directories and files consume.

# Summarize current directory size
du -sh .

# Show sizes of immediate subdirectories
du -sh */

# Show the 10 largest directories under /home
du -h /home --max-depth=2 | sort -rh | head -10

# Show size of a specific directory
du -sh ~/Documents

# Find the biggest files (uses find + du)
find /home -type f -exec du -h {} + 2>/dev/null | sort -rh | head -20

💡 Friendly Alternative: ncdu

ncdu (NCurses Disk Usage) is an interactive disk usage explorer — think of it as a terminal version of WinDirStat or Disk Utility:

# Install it
sudo apt install -y ncdu

# Scan and explore a directory
ncdu /home

# Navigate with arrow keys, press 'd' to delete, 'q' to quit

Memory (free)

free shows total, used, and available RAM and swap space.

# Human-readable (MB/GB)
free -h

# Watch memory usage update every 2 seconds
watch -n 2 free -h

Example Output

               total        used        free      shared  buff/cache   available
Mem:           15Gi       4.4Gi       8.0Gi       312Mi       3.1Gi       10Gi
Swap:         2.0Gi          0B       2.0Gi

Understanding the columns:

  • total — total physical RAM installed
  • used — RAM actively in use by programs
  • free — completely unused RAM
  • buff/cache — RAM used by the kernel for caching (automatically freed when apps need it)
  • available — the actual amount of RAM available for new programs (free + reclaimable cache). This is the number that matters most.
  • Swap — disk space used as overflow "memory" when RAM runs out (much slower than real RAM)

🐧 "Free" vs "Available"

Linux aggressively caches data in RAM to speed things up. Low "free" memory is normal and healthy — it means Linux is making good use of your RAM. What matters is available memory. If that drops near zero and swap starts filling up, you genuinely need more RAM (or need to close some programs).

CPU Information

# Detailed CPU information
lscpu

# Quick summary: model name
lscpu | grep "Model name"

# Number of CPUs/cores
nproc

# Real-time CPU usage per core
# (in htop, or:)
mpstat -P ALL 1  # needs sysstat: sudo apt install sysstat

Key lscpu Fields

Architecture:             x86_64
CPU(s):                   8
Thread(s) per core:       2
Core(s) per socket:       4
Model name:               Intel(R) Core(TM) i7-10700 @ 2.90GHz
CPU max MHz:              4800.0000
Virtualization:           VT-x
L1d cache:                256 KiB
L2 cache:                 2 MiB
L3 cache:                 16 MiB

Storage Devices

# List block devices (disks and partitions) in a tree
lsblk

# With filesystem info
lsblk -f

# Detailed partition info
sudo fdisk -l

# List USB devices
lsusb

# List PCI devices (graphics cards, network adapters, etc.)
lspci

# Just the graphics card
lspci | grep -i vga

Example lsblk Output

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 238.5G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0 234.0G  0 part /
└─sda3   8:3    0   4.0G  0 part [SWAP]
sdb      8:16   0 931.5G  0 disk
└─sdb1   8:17   0 931.5G  0 part /home

This shows two physical disks (sda and sdb) with their partitions and mount points.

💡 Comprehensive Hardware Report

# Full hardware inventory (needs root)
sudo lshw -short

# Or for a detailed report:
sudo lshw -html > hardware_report.html

lshw gives you everything: CPU, memory modules, disks, network cards, USB controllers — a one-stop hardware report.

System Information

# Kernel and OS details
uname -a

# Just the kernel version
uname -r

# Pretty system summary (if installed)
hostnamectl

# Ubuntu-specific version info
lsb_release -a
# or:
cat /etc/os-release

# Hostname
hostname

Example hostnamectl Output

 Static hostname: ray-desktop
       Icon name: computer-desktop
         Chassis: desktop
      Machine ID: a1b2c3d4e5f6...
         Boot ID: f6e5d4c3b2a1...
Operating System: Ubuntu 24.04.2 LTS
          Kernel: Linux 6.8.0-48-generic
    Architecture: x86-64
 Hardware Vendor: System manufacturer
  Hardware Model: System Product Name

🐧 All-in-One: neofetch

If you installed neofetch in the previous lesson's exercises, run it for a beautiful summary of your system — distro, kernel, CPU, GPU, memory, shell, resolution, and more, complete with your distro's logo in ASCII art.

sudo apt install -y neofetch
neofetch

Uptime and Logs

# How long the system has been running
uptime

# More readable uptime
uptime -p
# Output: up 5 hours, 32 minutes

# When was the system last booted?
who -b

# Recent boot history
last reboot | head -5

# View system logs (most recent messages)
journalctl -xe

# Follow live log output (like tail -f)
journalctl -f

# Logs from this boot only
journalctl -b

# Logs from a specific service
journalctl -u ssh.service --since "1 hour ago"

💡 dmesg — Kernel Messages

dmesg shows messages from the Linux kernel — useful for debugging hardware issues, driver problems, or USB device detection:

# View kernel messages (most recent last)
sudo dmesg | tail -30

# Follow new kernel messages in real time
sudo dmesg -w

# Filter for USB-related messages
sudo dmesg | grep -i usb

Exercises

🏋️ Exercise 1: Disk Health Check

  1. Check overall disk space: df -h
  2. Find the 5 largest directories in your home: du -h ~ --max-depth=1 | sort -rh | head -5
  3. Check your home directory size: du -sh ~

🏋️ Exercise 2: System Snapshot

Build a quick system report — run each command and note the results:

# OS and kernel
lsb_release -ds && uname -r

# CPU
lscpu | grep "Model name"

# RAM
free -h | grep Mem

# Disk
df -h / | tail -1

# Uptime
uptime -p

🏋️ Exercise 3: Hardware Discovery

  1. List storage devices: lsblk
  2. List USB devices: lsusb
  3. Find your graphics card: lspci | grep -i vga
  4. Get a compact hardware summary: sudo lshw -short

🏋️ Exercise 4: Monitor Memory Over Time

# Watch memory usage update every second
watch -n 1 free -h

# In another terminal, open a large application
# Watch the memory numbers change

# Press Ctrl+C to stop watching

Knowledge Check

❓ Question 1

Which command shows free space on all mounted filesystems?

❓ Question 2

In free -h output, which column tells you how much RAM is actually usable by new programs?

❓ Question 3

What does du -sh ~/Documents show?

❓ Question 4

Which command gives you a quick overview of CPU model, cores, and architecture?

Summary

🎉 Key Takeaways

  • df -h shows filesystem free space; du -sh shows directory sizes
  • free -h shows RAM usage — watch the available column, not "free"
  • lscpu, lsblk, lspci, lsusb reveal your hardware
  • uname -a and hostnamectl show OS and kernel details
  • journalctl and dmesg help you read system and kernel logs
  • ncdu and neofetch are helpful extras worth installing

🍎 On macOS

df -h, du -sh, uname -a, and dmesg work on macOS. Key differences:

  • free doesn't exist — use vm_stat or top -l 1 | head -n 10 for memory info
  • lscpu, lsblk, lspci, lsusb don't exist — use sysctl -a or system_profiler SPHardwareDataType
  • hostnamectl doesn't exist — use scutil --get ComputerName
  • journalctl doesn't exist — use log show or the Console app
  • Use diskutil list instead of lsblk to see disks and partitions
  • Install ncdu and neofetch via brew install ncdu neofetch

🚀 What's Next?

The final piece of system administration: services and systemctl — how to start, stop, enable, and manage the background services that keep your system running.