Bytes

A Service and a CLI conversion tool for file sizes.

Usage

You can use Bytes in a few ways.

First, just pass a number representing bytes to it. It will find the human-readable representation of it, ranging from Kilobytes to Yottabytes. Example:

bytes.rb 10938457612
=> 10.19GB

This is the same as the “to human” argument, unless the number already has a size name in it (245mb), in which case it would just return the input. If you add “to machine” to a number like that, you’ll get the byte equivalent back:

bytes.rb 245mb to machine
256901120

You can also specify what multiplier to use for machine-to-human conversion:

bytes.rb 10938457612 in mb
=> 10431.73MB

Human-to-human works the same way:

bytes.rb 245mb in kb
=> 250880.00KB

The script works with STDIN pipes or command line arguments, the former making it better for use in a Service. It will also look for its recongized syntaxes surrounded by parentheses in a larger block of text, so you can use it just like SearchLink:

The file had a size of (24mb to machine), which converted to (25165824 to human) (that’s (24mb in kb) in Kilobytes).

Piped to bytes.rb, that becomes:

The file had a size of 25165824, which converted to 24.00MB (that’s 24576.00KB in Kilobytes).

I don’t know how many people will ever have a use for this, but I liked the regex enough that I figured I should share it1. Download the System Service below, or grab the command-line script on GitHub.

To use the script, just make it executable and put it in your path. To use the Service, unzip and double click it to install, then select text containing its syntax and right click.

Bytes Service v1

Convert file sizes between machine and human-readable formats

Published 11/03/14.

Updated 11/03/14. Changelog

DonateMore info…


  1. The actual genesis of this was prepping for a recording of Random Trek where Data says he has 800 quadrillion bytes of memory capacity. I was curious what that translated to… (it’s 88.82 petabytes) 

Related Projects