Are you grappling with a sluggish Linux system or receiving ominous warnings about high disk usage? Fear not! This guide will walk you through straightforward commands to pinpoint those storage-hogging culprits.
Checking Overall Disk Usage
To start our journey, let’s get a bird’s-eye view of your disk space:
df -h
This command provides a human-readable summary of disk usage across various partitions. Look for the “Use%” column to spot any partitions nearing full capacity.
Refer to the below blog for a detailed explanation of the DU command and its usage:
Locating Large Directories
Now that you know your overall disk status, let’s zoom in on specific directories guzzling space:
du -h --max-depth=1 /
This command lists the sizes of top-level directories. Navigate to the largest ones using cd
and repeat the process until you identify the space hogs.
Digging Deeper with Find
Once you’ve isolated a suspicious directory, use the find
command to locate large files within it:
find /path/to/directory -type f -size +100M
Replace /path/to/directory
with the actual path and adjust the size threshold as needed. This command finds files larger than 100 megabytes.
Sorting and Summarizing
To sort directories by size, aiding in the identification of the biggest culprits:
du -h --max-depth=1 / | sort -hr
This command lists directories in descending order, helping you focus on the largest ones first.
Clean-Up Commands
Once you’ve identified space-consuming files or directories, consider these commands for efficient cleanup:
- Removing a file:
rm /path/to/file
- Removing a directory and its contents:
rm -r /path/to/directory
Be cautious when using these commands to avoid unintentional data loss.
With these simple commands, you can easily navigate and manage high disk usage on your Linux system. Regularly monitoring and optimizing your storage will keep your system running smoothly.