Skip to content

Instantly share code, notes, and snippets.

@l0b0
Created December 9, 2010 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l0b0/734829 to your computer and use it in GitHub Desktop.
Save l0b0/734829 to your computer and use it in GitHub Desktop.
Unformat disk size
# Convert strings like '5kb', '2MB' and '500TB' to their byte equivalents
# Based on http://stackoverflow.com/questions/4399475/unformat-disk-size-strings
unformat()
{
echo $1 | sed -e 's/b//i;s/k/*1000/i;s/m/*1000000/i;s/g/*1000000000/i;s/t/*1000000000000/i' | bc
}
@l0b0
Copy link
Author

l0b0 commented Feb 1, 2012

Might want to add a clause for the i character, to support the difference between ISO KiB (1024) and KB (1000).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment