pretty-bytes
Convert bytes to human-readable string
TLDR
Convert numeric bytes value to a human-readable string
Convert numeric bytes value from stdin to a human-readable string
Display help
SYNOPSIS
pretty-bytes [number] [options]
PARAMETERS
number
The number of bytes to format. This is the only mandatory parameter.
-s, --signed
Display plus sign for positive numbers. Default: `false`
-u, --unicode
Use Unicode symbols instead of ASCII. Default: `false`
-b, --binary
Use binary units (KiB, MiB, etc.) instead of decimal (KB, MB, etc.). Default: `false`
-sp, --space
Display a space between value and unit. Default: `false`
-l, --locale
Format the number using the given locale. Example: `de` for German. Default: uses system's locale
-L, --localeOptions
Provide locale options as a JSON string. Example: `{"minimumFractionDigits": 2}`. Requires `--locale` to be set.
DESCRIPTION
The `pretty-bytes` command (and underlying library) is designed to convert byte sizes into easily understandable, human-readable strings. Instead of displaying sizes in raw bytes, it automatically scales the output to use appropriate units (e.g., KB, MB, GB, TB) and formats the number for clarity. This makes it much easier for users to quickly grasp the magnitude of a file size or storage capacity. The tool is commonly used in shell scripts or other applications where presenting byte sizes in a user-friendly manner is essential. It automatically handles pluralization of units and includes optional flags for controlling output format, such as displaying the space between value and unit. The core functionality comes from the javascript library but is conveniently packaged into a CLI for Linux/Unix systems. The primary benefit is enhanced readability and user experience when dealing with byte-related information.
It's especially helpful when you do not know the order of magnitude of the size in advance, as it dynamically picks the correct unit.
EXAMPLES
pretty-bytes 1337
Output: 1.34 kB
pretty-bytes 1337 -s
Output: +1.34 kB
pretty-bytes 1337 -u
Output: 1.34 kiB
pretty-bytes 1337 -b
Output: 1.30 KiB
pretty-bytes 1337 -sp
Output: 1.34 kB
pretty-bytes 1337 -l de
Output: 1,34 kB
pretty-bytes 1337 -l de -L '{"minimumFractionDigits": 2}'
Output: 1,34 kB
HISTORY
The `pretty-bytes` command is derived from a JavaScript library of the same name, designed for Node.js environments. It gained popularity due to its ease of use and consistent output formatting. The CLI wrapper allows developers and system administrators to leverage this functionality directly from the command line. Its adoption has been driven by the need for a standardized and user-friendly way to display byte sizes across different platforms and tools.