System Resource and Disk Management in Linux: Monitor, Optimize, and Prepare Your Storage
As your Linux system grows with files, processes, and applications, it’s critical to keep an eye on how resources like disk space, memory, and CPU are being used. Whether you’re running a personal Linux machine or managing production servers, understanding resource utilization helps you avoid system slowdowns, crashes, and data loss.
In this guide, we’ll walk you through essential Linux tools to:
-
Monitor disk space and memory usage
-
Analyze CPU load
-
Manage partitions and mount drives
By the end, you’ll know how to detect issues, free up space, and prepare new storage devices—all using the Linux command line.
Why System and Disk Management Matters
Efficient system management isn’t just for sysadmins—it’s for anyone who wants their Linux system to run smoothly and predictably.
Without regular monitoring:
-
Disks can fill up unexpectedly
-
Systems can slow down due to memory exhaustion
-
CPU-heavy processes can overload servers
-
You might lose data or experience system failure
Fortunately, Linux provides robust tools to prevent that.
📦 Checking Disk Usage with df
and du
📊 df
– Check Free Disk Space
df
stands for “disk free.” It shows available and used disk space on all mounted filesystems.
🔹 Basic Usage:
df -h
-h
= human-readable (e.g., MB, GB)
🔹 Example Output:
Filesystem Size Used Avail Use% Mounted on</code
/dev/sda1 50G 35G 12G 75% /
/dev/sdb1 100G 90G 10G 90% /data
Use df
to check which partitions are filling up and take action before hitting 100%.
📁 du
– Analyze Directory Size
While df
shows disk partitions, du
(disk usage) breaks down the space used by files and folders.
🔹 Check Size of a Directory:
du -sh /home/username
-
-s
= summary -
-h
= human-readable
🔹 Find What’s Taking Up Space:
du -h /var | sort -hr | head -10
This shows the 10 largest directories under /var
.
💾 Checking Memory and CPU Load
🧠 View Memory Usage with free
The free
command displays used, free, and cached memory.
🔹 Usage:
free -h
🔹 Example Output:
total used free shared buff/cache available
Mem: 8.0G 3.2G 1.2G 256M 3.6G 4.3G
Swap: 2.0G 0B 2.0G
Use this to understand how much memory your applications are consuming and whether swap space is being used.
⚙️ Monitor CPU Load with top
or uptime
🔹 top
Displays CPU usage per process and system-wide load averages.
🔹 uptime
Quickly shows system load averages over the last 1, 5, and 15 minutes.
uptime
Example:
12:40:19 up 3 days, 2:10, 2 users, load average: 0.85, 1.09, 1.24
Lower load averages are better. A load average near or over the number of CPU cores indicates a potentially overloaded system.
🧱 Managing Partitions and Mounting Drives
If you’re adding a new hard drive or USB device, you’ll need to understand partitions and how to mount them.
🛠️ Basic Partitioning with fdisk
or parted
🔹 List Disks:
sudo fdisk -l
🔹 Enter Partition Mode:
sudo fdisk /dev/sdb
Inside fdisk
, you can:
-
n
– Create a new partition -
d
– Delete a partition -
w
– Write changes
For GPT partitions and large disks, use parted
.
🔗 Mounting and Unmounting Drives
To use a drive, it must be mounted to a directory.
🔹 Mount a Filesystem:
sudo mount /dev/sdb1 /mnt
🔹 Unmount:
sudo umount /mnt
You can make the mount permanent by adding it to /etc/fstab
.
Real-World Use Cases
✅ 1. Investigate Why Disk Space Is Running Low
df -h
du -h /home | sort -hr | head -10
✅ 2. Check If Your Server Needs a RAM Upgrade
free -h
top
✅ 3. Mount a USB Drive and Transfer Files
sudo mount /dev/sdc1 /mnt
cp /mnt/photos/* ~/Pictures/
sudo umount /mnt
✅ 4. Prepare a New SSD for Data Storage
sudo fdisk /dev/sdd
sudo mkfs.ext4 /dev/sdd1
sudo mount /dev/sdd1 /data
These basic workflows help you maintain system performance, handle storage devices safely, and ensure you’re never caught off guard by resource exhaustion.
What’s Next?
By now, you’ve seen how Linux makes it easy to inspect, optimize, and manage system resources. But wouldn’t it be even better if you could automate these checks?
In the next blog post, we’ll dive into shell scripting—where you’ll learn how to:
-
Automate repetitive system checks
-
Combine commands into powerful workflows
-
Schedule routine maintenance tasks
Want to save time and boost your productivity in the Linux terminal? Mastering shell scripting!