How to Check Disk Usage and Find Large Files on Linux

After setting up a new Linux server, you’ll want to know how to check what’s taking up space. Disk space is often the weakest link in system stability
How to Check Disk Usage and Find Large Files on Linux
After setting up a new Linux server, you’ll want to know how to check what’s taking up space. Disk space is often the weakest link in system stability. Here’s how to identify space hogs quickly.
Basic Disk Space Check
The fastest way to see overall disk usage is df -h. The -h flag shows sizes in human-readable format.
df -hThis shows mounted filesystems, their total size, used space, free space, and mount points. Monitor /var/log and /home – they’re common culprits for filling up /.
Check Disk Usage Per Directory
Use du (disk usage) to see how much space each directory consumes. Without arguments, it checks the current directory. Add -h for readability and -s to show summaries per directory.
du -sh *This lists every item in the current directory with its total size. Pipe it through sort -h to see the largest first:
du -sh * | sort -hFind the 10 Largest Files
Use find to search for files and sort to order them by size. The following command starts from /, skips directories (-type f), and prints only files with these syntax:
find / -type f -exec du -sh {} + 2>/dev/null | sort -h | tail -n 10Breakdown:
-exec du -sh {} +runsduon every found file and prints formatted sizes.2>/dev/nulldismisses permission errors.sort -hsorts by human-readable sizes.tail -n 10shows the 10 largest.
Warning: Running find as root can be destructive. Use sudo only if necessary.
Identify Old Log Files
Logs in /var/log often grow indefinitely. Check which service logs are largest:
sudo du -sh /var/log/* | sort -hFor example, journalctl logs can take up gigabytes. Clear old logs with:
sudo journalctl --rotate --vacuum-time=7dThis purges logs older than seven days.
Cleaning Up Temporary Files
The tmp directory (/tmp) is for temporary files. While it’s safe to clear, avoid deleting files owned by running processes. Use lsof to check active files:
lsof /tmpFor older temporary files not in use:
sudo rm -rf /tmp/*Warning: This command is safe for /tmp, but never delete files from other directories without verification.
Advanced: Track Disk Usage Over Time
For ongoing monitoring, write a script that runs df -h periodically and logs the output. Use cron to automate it:
#!/bin/bash
df -h >> /var/log/disk_usage.logAdd to crontab to run every hour:
crontab -eAdd this line:
0 * * * * /path/to/your/script.shSummary
- Use
df -hto check total disk usage. - Run
du -sh * | sort -hto list directory sizes. - Find large files with
find / -type f -exec du -sh {} + | sort -h | tail -n 10. - Monitor
/var/logfor bloated logs and clear them withjournalctl. - Regularly clean
/tmp, but avoid deleting active files.
These commands, used together, help you maintain disk health and prevent system slowdowns.

Written by Robin te Hofstee
Technology enthusiast with a deep love for programming. Sharing practical guides on React, Next.js, Linux and self-hosting.
Related Posts
Securing a Next.js Application in Production
Securing a Next.js app in production means protecting the client bundle, the server, and the data flow. This post shows how to lock down Content‑Secur
How Git Works
Git is a distributed version control system that allows multiple people to collaborate on a project while maintaining a complete history of all change
Securing Apache2 Web Server Against Attacks
This tutorial provides a step-by-step guide to securing your Apache2 web server against common vulnerabilities and attacks. Follow these best practice


