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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

ALL ARTICLES & CATEGORIES

CCTV

Follow this category by RSS

Data Privacy

Follow this category by RSS

Digital Analytics

Follow this category by RSS

Digital Marketing

Follow this category by RSS

IT & Networks

Follow this category by RSS

Raspberry PI

Follow this category by RSS

Smart Home

Follow this category by RSS

Web Development

Follow this category by RSS

Wordpress Hacks

Follow this category by RSS