Skip to content

Instantly share code, notes, and snippets.

@ferbass
Last active October 26, 2022 02:53
Show Gist options
  • Save ferbass/ec4d103240e720eb24f8d65454886726 to your computer and use it in GitHub Desktop.
Save ferbass/ec4d103240e720eb24f8d65454886726 to your computer and use it in GitHub Desktop.
Convert /proc/meminfo to KB, MB and GB as appropriate
# convert any kB lines to MB:
awk '$3=="kB"{$2=$2/1024;$3="MB"} 1' /proc/meminfo
# converts to gigabytes:
awk '$3=="kB"{$2=$2/1024^2;$3="GB";} 1' /proc/meminfo
# convert to MB or GB as appropriate:
awk '$3=="kB"{if ($2>1024^2){$2=$2/1024^2;$3="GB";} else if ($2>1024){$2=$2/1024;$3="MB";}} 1' /proc/meminfo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment