You are not logged in.
Hello! Anyone can change this script from MB to GB. I use it to display memory "used/total (%percentages)"
It display something like:
423/1979MB (21%)
But wish it display
423/1.9Gi (21%) or 423/2G (21%)
I was looking on the Internet, although I found some possibilities i could not achieved the goal.
So this is the command, anyone can fix it please?
free -m | awk 'NR==2{printf "%s/%sMB (%u%%)\n", $3,$2,$3*100/$2 }'
Thank you!
Edit:
free -h | awk '/Mem\:/ { print $2 }'
This is good add, but i find it difficult to attach on the above code.
Last edited by Nili (2020-08-28 14:36:46)
Tumbleweed (Server) | KDE Plasma (Wayland)
Offline
free -h | awk 'NR==2{printf "%s/%s",$3,$2}'; free -m |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
since it adds Units to each field according to size and math does not need them.
Offline
Very accurate JCN-9000! Exactly such i wanted. Thank you very much bro!
Tumbleweed (Server) | KDE Plasma (Wayland)
Offline
NICE!!!!
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
Another request, sorry, but seems that it can be done.
Can we remove those "i" from "Mi / Gi" to "M" or "G" so
370Mi/1.9Gi (18%)
to be
370M/1.9G (18%)
^Such would be a totally human reader.
Tumbleweed (Server) | KDE Plasma (Wayland)
Offline
a slight change to JCN-9000's line will do it:
free -h --si | awk 'NR==2{printf "%s/%s",$3,$2}'; free -h |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
28 Aug 20 @ 12:49:39 ~
$ free -h --si | awk 'NR==2{printf "%s/%s",$3,$2}'; free -h |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
1.1G/14G (8%)
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
F=$(free -h | awk 'NR==2{printf "%s/%s",$3,$2}'; free -m |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }')
echo ${F//i}
1.0G/31G (3%)
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Thanks S11
This is the best solution
free -h --si | awk 'NR==2{printf "%s/%s",$3,$2}'; free -m | awk 'NR==2{printf" (%u%%)\n",$3*100/$2 }'
I only changed from your code "free -h" to "free -m" because free -h gave me
358M/2.0G (18842%)
Now i have ideally completed results.
MM: » 391M/2.0G (19%)
Thanks guys, you fixed to the best possible
Tumbleweed (Server) | KDE Plasma (Wayland)
Offline
Interesting!
All three of these work for me:
28 Aug 20 @ 14:32:38 ~
$ free -h --si | awk 'NR==2{printf "%s/%s",$3,$2}'; free -h |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
1.0G/14G (7%)
28 Aug 20 @ 14:33:11 ~
$ free -h --si | awk 'NR==2{printf "%s/%s",$3,$2}'; free -m |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
1.0G/14G (7%)
28 Aug 20 @ 14:33:19 ~
$ free -h --si | awk 'NR==2{printf "%s/%s",$3,$2}'; free |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
1.0G/14G (7%)
28 Aug 20 @ 14:33:35 ~
$
BUT what's important - what works for you.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
free -h calculate percentages on byte range to me. Like the one
1 (36421%)
2 ok (35%)
3 ok (35%)
So yeah, whatever it works
Tumbleweed (Server) | KDE Plasma (Wayland)
Offline
I know it's not what you wanted but look at these:
28 Aug 20 @ 16:03:47 ~
$ free --gibi | awk 'NR==2{printf "%s/%s",$3,$2}'; free |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
1/13 (7%)
28 Aug 20 @ 16:04:09 ~
$ free --giga | awk 'NR==2{printf "%s/%s",$3,$2}'; free |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
1/14 (7%)
28 Aug 20 @ 16:04:15 ~
$ free --mebi | awk 'NR==2{printf "%s/%s",$3,$2}'; free |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
1071/14019 (7%)
28 Aug 20 @ 16:04:33 ~
$ free --mega | awk 'NR==2{printf "%s/%s",$3,$2}'; free |awk 'NR==2{printf " (%u%%)\n",$3*100/$2 }'
1123/14700 (7%)
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
Woah! how many choices, S11 you're incredible. I'll save two or three of those.
I'm already overwhelmed
Tumbleweed (Server) | KDE Plasma (Wayland)
Offline
Noooooo not me, thank JCN-9000 he deserves the credit.
I'm just playing with his line of code that I would never even guessed at and the "free" manpage.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
Both of you who offers your help are sincerely thanked. I have very good output memory usages now.
Tumbleweed (Server) | KDE Plasma (Wayland)
Offline
Both of you who offers your help are sincerely thanked....
"And me!", damo squeaked plaintively
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
"And me!", damo squeaked plaintively
Certainly! @admin, @mod @members and their help is the greatest value a distro has. Even if one is forgotten without being mentioned, it is not done intentionally. A part of his help or codes that lives in any system is always remembered in a way by the end-user.
Tumbleweed (Server) | KDE Plasma (Wayland)
Offline