LW IT Solutions
« Blog Overview /IT & Networks/Tutorials / Tutorial: Managing Disk Space: Finding Largest Files...
This post in other languages:

Tutorial: Managing Disk Space: Finding Largest Files via SSH on Ubuntu/Debian

Tutorial: Managing Disk Space: Finding Largest Files via SSH on Ubuntu/Debian

Effective server maintenance requires regular monitoring of disk space usage. When a disk partition nears capacity, identifying the largest files is the most efficient way to reclaim space. The following guide details two methods for locating large files on Ubuntu and Debian systems using the command line.

Method 1: Using the find Command

The find command is highly efficient for locating files that exceed a specific size threshold. This is useful when searching for files larger than a defined limit (e.g., 500MB).

Diagram for the article: Method 1: Using the find Command, Method 2: Using the du and sort Commands, Sample Output
The sequence from the article in 3 steps: Method 1: Using the find Command, Method 2: Using the du and sort Commands, Sample Output.
find /path/to/directory -type f -size +500M -exec ls -lh {} +
  • /path/to/directory: The starting point for the search.
  • -type f: Specifies that only files (not directories) should be listed.
  • -size +500M: Filters for files larger than 500 Megabytes.
  • -exec ls -lh {} +: Executes the ls -lh command to display details.

Method 2: Using the du and sort Commands

For identifying the “Top N” largest files or directories, combining du (disk usage) with sort is the preferred approach. This provides a ranked list.

du -ah /path/to/directory | sort -rh | head -n 10
  • du -ah: Calculates disk usage for all files and directories in human-readable format.
  • sort -rh: Sorts the results by size in reverse (largest first) and interprets human-readable numbers (e.g., K, M, G).
  • head -n 10: Restricts the output to the top 10 results.

Sample Output

The execution of the du command produces an output similar to the following:

4.2G    /var/lib/docker/containers/a1b2c3d4/a1b2c3d4-json.log
2.1G    /var/log/syslog
1.8G    /home/user/backups/db_backup.sql
950M    /usr/share/zoneinfo/data.bin
...
Lukas Wojcik

Lukas Wojcik

Systems architect and technology enthusiast specializing in scalable tracking solutions, GMP Stack (GA4 & GTM), and robust backend architectures. Advocate for clean code and privacy-first design.

Get in Touch

Briefly describe your project or inquiry for a tailored response. This site is protected by reCAPTCHA.

2 comments

  1. Pawel Strzelczyk

    Both commands belong in the muscle memory of anyone maintaining a server,and the example output naming the Docker log first is painfully accurate.

    Neither helps in the case we hit last month, though: a partition reported as full while both commands found nothing worth deleting. Is there a third thing to check?

    1. Lukas Wojcik Author

      Two, and they cover almost every case where the usual pair comes up empty.

      The first is inodes: df -i. A filesystem can be sixty percent full by bytes and completely out of inodes, at which point writes fail with the same message as a full disk. The cause is always the same shape — millions of tiny files in one place, typically a mail queue, a session directory or an unrotated cache. Neither find -size nor du ranks them, because individually they are nothing.

      The second is deleted-but-open files: a log that was removed while a process still holds it keeps its blocks until that process closes or restarts. df counts the space, du cannot see the file, and the discrepancy between the two is the tell. lsof +L1 lists them. Between those two checks and the two in the article, the disk has nowhere left to hide.

Write a comment

The email address is not published. Required fields are marked with an asterisk.

ALL ARTICLES & CATEGORIES

CCTV

Follow this category by RSS

Cloud & AI

Follow this category by RSS

Data Privacy

All 11 articles in this category Follow this category by RSS

Digital Analytics

All 44 articles in this category Follow this category by RSS

Digital Marketing

All 25 articles in this category Follow this category by RSS

IT & Networks

All 15 articles in this category Follow this category by RSS

Raspberry PI

Follow this category by RSS

Smart Home

All 11 articles in this category Follow this category by RSS

Web Development

Follow this category by RSS

WordPress Plugins & Tricks

Follow this category by RSS