Quantcast
Viewing latest article 7
Browse Latest Browse All 21

Answer by FJL for A standard tool to convert a byte-count into human KiB MiB etc; like du, ls1

Actually, there is a utility that does exactly this. I know cos it was me wot wrote it. It was written for *BSD but ought to compile on Linux if you have the BSD libraries (which I believe are common).

I've just released a new version, posted here:

http://blog.frankleonhardt.com/2015/freebsd-hr-utility-human-readable-number-filter-man-page/

It's called hr, and it will take stdin (or files) and convert numbers to human-readable format in a way that is (now) exactly the same as ls -h and so on, and it can select individual feeds in lines, scale pre-scaled units (e.g. if they're in 512-byte blocks convert them to Mb etc), adjust column padding, and so on.

I wrote it a few years ago because I thought trying to write a shell script, although intellectually interesting, was also utter madness.

Using hr, for example, you can easily get a sorted list of directory sizes (which come out in 1Kb units and need shifting before converting) with the following:

du -d1 | sort -n | hr -sK

While du will produce -h output, sort won't sort by it. The addition of -h to existing utilities is a classic case of not following the unix philosophy: have simple utilities doing defined jobs really well.


Viewing latest article 7
Browse Latest Browse All 21

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>