2

Could you help me to modify the following one-liner to get more precise memory usage - right now it's just an integer I would like to include first value after coma.

free -m | awk '/Mem:/ {tot = $2;} /cache:/{printf "%d\n", $3 / tot * 100}'

Thank you

HTF
  • 3,148
  • 14
  • 52
  • 82

1 Answers1

5

Your %d format specifier is forcing printf to print an integer value. If you change it to %f then it would print the full number. You can use %.nf to limit the number of decimal places printed so %.1f would print one decimal place.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • Already posted above, although with less explanations ^_^ – ripat Jun 06 '12 at 19:49
  • 3
    @ripat Should have made it an answer :). If the correct answer is in a comment, then it's fair game to be "reposted" as an answer, since an OP cannot mark a comment as "accepted". – MDMarra Jun 06 '12 at 19:56
  • @MDMarra. I agree. My apologies but the answer was so short and obvious... – ripat Jun 07 '12 at 14:49
  • @ripat: obvious to you and I because we know the answer but clearly not obvious to everyone. As you can see, answers don't have to be short either, I think longer is better. – user9517 Jun 07 '12 at 14:52