compsize
Determine the compression ratio of filesystems
TLDR
Calculate the current compression ratio for a file or directory
Don't traverse filesystem boundaries
Show raw byte counts instead of human-readable sizes
SYNOPSIS
compsize [options] [path...]
PARAMETERS
-d, --debug
Enable debugging output. This may generate a lot of output.
-x, --exclude
Exclude files matching the given
-n, --numeric
Show numeric output, without size suffixes (e.g., KB, MB, GB).
-i, --individual
Show information for each individual file (slow).
-q, --quiet
Suppress error messages.
-v, --verbose
Show verbose output.
-h, --help
Display help message and exit.
-V, --version
Display version information and exit.
[path...]
Path to files or directories to analyse. Defaults to current directory
DESCRIPTION
The compsize command is a utility used to analyze the disk usage of files on a Btrfs filesystem, comparing the apparent file size with the actual space consumed due to compression and deduplication. It provides insights into the effectiveness of these features by showing the logical size of files and the physical space they occupy on the disk. compsize is especially useful in identifying files that benefit most from compression and for understanding how deduplication is reducing storage footprint. It can be used to analyze entire directories or specific files, providing a summary of the space savings achieved.
The utility works by querying the Btrfs filesystem metadata to determine the allocated disk blocks for each file. It then compares this with the file's logical size, reported by standard file system tools, to calculate the space savings percentage. compsize offers a valuable way to monitor and optimize storage utilization within Btrfs environments.
CAVEATS
compsize only works on Btrfs filesystems. The reported values may not be entirely accurate, as they depend on the filesystem metadata and compression algorithms used. Results can vary after disk defrag. It can be slow when used against many small files when used with the -i/--individual flag. Requires appropriate permissions to access file metadata.
EXAMPLE USAGE
To check the compression ratio of the current directory:
compsize .
To check compression ratio of a specific file:
compsize /path/to/your/file
To check compression ratio of all files in directory individually:
compsize -i /path/to/your/directory