Monday, July 24, 2017

Today I Learned (TIL)

Today I Learned (TIL) is a series of posts that contain bit sized information that I learned and found to be worthy of sharing with others and keep as a note to myself.

For the last couple of years, I had been devoting most of my time in building the start-up, Zycada Networks, that I co-founded. It makes me happy to share my knowledge. So I would like to get back to the habit of writing blog posts regularly on interesting stories, tips-and-tricks, new ideas, technology trends, etc. TIL is one part of doing it.

TIL: Sort human friendly values

Sorting numeric values in the input is easy. It just takes "sort -n". But what if the input contains human friendly units. For intance, "5G", "3M", "4K", etc. There is a flag to recognize and sort based on the human friendly units: "-h".

Incorrect: du -h | sort -nr
Correct: du -h | sort -rh

Caveat: "sort -h" works only on upper-case units. "K" will be treated as kilos, but "k" will not be!