Announcement

Collapse
No announcement yet.

Extracting used memory as a percentage from free -m

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Extracting used memory as a percentage from free -m

    This is just some code to get used memory as a percentage:

    Code:
    free -m | awk ' $1 == "Mem:" { print "(("$3 "/" $2 ")" "*100)"}' | bc -l | cut -d '.' -f -1
    Can it be simplified?
    Last edited by chimak111; Dec 29, 2020, 08:26 AM.
    Kubuntu 20.04

    #2
    Here's a version that does all the dirty work in awk:
    Code:
    free -m | awk '$1 == "Mem:" { printf "%.0f\n", (($3 / $2 ) *100)}'

    Comment


      #3
      Originally posted by andystmartin View Post
      Here's a version that does all the dirty work in awk:
      Code:
      free -m | awk '$1 == "Mem:" { printf "%.0f\n", (($3 / $2 ) *100)}'
      Great! Thank you!
      Kubuntu 20.04

      Comment

      Working...
      X