DEV Community

Traliran
Traliran

Posted on

du-rank: A Tiny and Ultra-Fast C Disk Usage Analyzer

When a server or laptop suddenly runs out of disk space, standard CLI tools like du require complex syntax, while heavy GUI apps aren't suitable for remote terminals. du-rank is a lightweight command-line tool designed for instant disk usage analysis on Linux and POSIX systems.

Why Choose du-rank for Disk Usage Analysis and RAM Efficiency?

Scanning millions of files often leads to high memory consumption in traditional utilities. du-rank solves this issue through zero-dependency C code and memory-efficient data structures.

Minimalist Tech Stack: Pure C with Zero External Dependencies

Written in clean POSIX C, the entire utility is contained within a single C source file.

  • Zero Dependencies: Relies solely on standard POSIX headers (<dirent.h>, <sys/stat.h>, <unistd.h>).

  • High Portability: Compiles effortlessly using any standard C compiler (gcc, clang) via Makefile.

  • Instant Execution: The resulting binary is just a few kilobytes and launches instantly.

Min-Heap Algorithm: Fixed Memory Footprint on Multi-Terabyte Drives

During standard scans, du-rank avoids storing the full file tree in memory. Instead, it utilizes a Min-Heap of a fixed size N (default N=10).

Memory is allocated only for the top-N largest items. This ensures an O(N) memory footprint, preventing Out-Of-Memory (OOM) crashes even when scanning multi-terabyte drives.

Key Features: Scanning Modes and Command-Line Options

du-rank delivers clear visual feedback directly in the terminal using ASCII/UTF-8 bar charts and optional ANSI colors.

Fast Scanning Workflows: --allsys, --usr, and --top

Analyze system drives or user folders with concise commands:

  • --allsys — scans the entire filesystem starting from / (automatically skipping pseudo-filesystems like /proc, /sys, /dev, and /run).

  • --usr — instantly checks the current user's home directory (~).

  • --top <N> — customizes the output to show the top N space-consuming targets.

Duplicate File Detection with --dubl-scan: Reclaim Wasted Space

One of the standout features is the built-in duplicate scanner activated via --dubl-scan:

$ du-rank --dubl-scan --usr
Enter fullscreen mode Exit fullscreen mode
  • Matching Strategy: Groups regular files matching by name, exact size, and modification time (mtime).

  • High Performance: Avoids reading file content from disk, ensuring near-instant scan completion.

  • Reclaimable Space: Calculates the exact amount of disk space you can recover by keeping one copy per group.

Measurement Accuracy: Why st_blocks Beats Apparent File Size

Many basic utilities report apparent file size (st_size), which can be inaccurate for sparse files or block-allocated storage.

du-rank measures actual allocated disk sectors using st_blocks (512-byte blocks). This delivers true disk usage figures identical to core system tools.

How to Build and Run du-rank from GitHub

Building du-rank requires only a C compiler and make:

# Clone the repository from GitHub
git clone https://github.com/Traliran/du-rank.git
cd du-rank

# Build the binary
make

# Analyze your home directory
./du-rank --usr

# Find top 5 space consumers in /var
./du-rank --top 5 /var
Enter fullscreen mode Exit fullscreen mode

Summary and Repository Links

du-rank is a practical utility for Linux admins, developers, and power users who value speed, accuracy, and minimal footprint.

GitHub Repository: Traliran/du-rank

Top comments (0)