Skip to content
Robin te Hofstee — Personal Blog
➜~neofetch

robin@blog

Name
Robin te Hofstee
Role
Full-stack developer, sysadmin & technical writer
Focus
homelab · Linux · self-hosting · Next.js
Posts
60 · latest Nov 17, 2026
Host
blog.robintehofstee.com
Links
github · rss · portfolio
➜curlblog.robintehofstee.com
➜~cat/blog/how-to-check-disk-usage-and-find-large-files-on-linux.mdx
←cd ~

How to Check Disk Usage and Find Large Files on Linux

Aug 14, 20263 minlinuxsecurityhackingcybersecuritycheatsheet

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.

bash
df -h

This 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.

bash
du -sh *

This lists every item in the current directory with its total size. Pipe it through sort -h to see the largest first:

bash
du -sh * | sort -h

Find 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:

bash
find / -type f -exec du -sh {} + 2>/dev/null | sort -h | tail -n 10

Breakdown:

  • -exec du -sh {} + runs du on every found file and prints formatted sizes.
  • 2>/dev/null dismisses permission errors.
  • sort -h sorts by human-readable sizes.
  • tail -n 10 shows 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:

bash
sudo du -sh /var/log/* | sort -h

For example, journalctl logs can take up gigabytes. Clear old logs with:

bash
sudo journalctl --rotate --vacuum-time=7d

This 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:

bash
lsof /tmp

For older temporary files not in use:

bash
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:

bash
#!/bin/bash
df -h >> /var/log/disk_usage.log

Add to crontab to run every hour:

bash
crontab -e

Add this line:

bash
0 * * * * /path/to/your/script.sh

Summary#

  • Use df -h to check total disk usage.
  • Run du -sh * | sort -h to list directory sizes.
  • Find large files with find / -type f -exec du -sh {} + | sort -h | tail -n 10.
  • Monitor /var/log for bloated logs and clear them with journalctl.
  • Regularly clean /tmp, but avoid deleting active files.

These commands, used together, help you maintain disk health and prevent system slowdowns.