Ljunggren.net [Google] *  [FB] *   [ChatGPT]  

Welcome to Ljunggren.net

The time in Sweden is approximately 2025-11-24 05:52:07

big2si

A simple php program that converts all big numbers from its standard in, into more human readable text.

I often use it to find big directories & files, typical usage:

du -bx /var/log | sort -n | tail | big2si

Or track rsync syncing a large set of files:

watch -d 'du -bx rsync_target | sort -n | tail -30 | big2si'

 

 

#!/usr/bin/php

<?php

function si($v,$dec=1) {

 $six=array('K','M','G','T','P','E','Are you nuts?');

 $sis='';

 while ($v>800) {

  $v=$v/1024.0;

  $sis=array_shift($six);

 }

 return (round($v*pow(10,$dec))/pow(10.0,$dec)).$sis;

}

 

function sicb($m) {

 return si($m[1],2);

}

 

$fp = fopen("php://stdin", "r") or die("can't read stdin");

while (!feof($fp)) {

    $line = fgets($fp);

    $line = preg_replace_callback('/([0-9]{3,})/','sicb',$line);

        echo "$line";

}