Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
4  
printf "%.1f\n" ? –  ripat Jun 6 '12 at 19:33
add comment

1 Answer

up vote 5 down vote accepted

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.

share|improve this answer
    
Already posted above, although with less explanations ^_^ –  ripat Jun 6 '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 6 '12 at 19:56
    
@MDMarra. I agree. My apologies but the answer was so short and obvious... –  ripat Jun 7 '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. –  Iain Jun 7 '12 at 14:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.