💾 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
dfanddu - Monitor memory usage with
free - Inspect CPU and hardware with
lscpu,lsblk, andlshw - View system and kernel info with
unameandhostnamectl - 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
| Column | Meaning |
|---|---|
Filesystem | The device or partition |
Size | Total capacity |
Used | Space currently occupied |
Avail | Space remaining |
Use% | Percentage full |
Mounted on | Where 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
- Check overall disk space:
df -h - Find the 5 largest directories in your home:
du -h ~ --max-depth=1 | sort -rh | head -5 - 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
- List storage devices:
lsblk - List USB devices:
lsusb - Find your graphics card:
lspci | grep -i vga - 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 -hshows filesystem free space;du -shshows directory sizesfree -hshows RAM usage — watch the available column, not "free"lscpu,lsblk,lspci,lsusbreveal your hardwareuname -aandhostnamectlshow OS and kernel detailsjournalctlanddmesghelp you read system and kernel logsncduandneofetchare helpful extras worth installing
🍎 On macOS
df -h, du -sh, uname -a, and dmesg work on macOS. Key differences:
freedoesn't exist — usevm_statortop -l 1 | head -n 10for memory infolscpu,lsblk,lspci,lsusbdon't exist — usesysctl -aorsystem_profiler SPHardwareDataTypehostnamectldoesn't exist — usescutil --get ComputerNamejournalctldoesn't exist — uselog showor the Console app- Use
diskutil listinstead oflsblkto see disks and partitions - Install
ncduandneofetchviabrew 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.