You are not logged in.

#1 2020-08-28 13:13:26

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 976
Website

[SOLVED] Memory Usage more human reader

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)


OS: Devuan GNU/Linux 4 (chimaera/ceres)
WM: Openbox / Tint2

Studio Ghibli

Offline

#2 2020-08-28 14:10:24

JCN-9000
Member
From: Turin, Italy
Registered: 2016-04-22
Posts: 10

Re: [SOLVED] Memory Usage more human reader

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

#3 2020-08-28 14:36:27

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 976
Website

Re: [SOLVED] Memory Usage more human reader

Very accurate JCN-9000! Exactly such i wanted. Thank you very much bro!


OS: Devuan GNU/Linux 4 (chimaera/ceres)
WM: Openbox / Tint2

Studio Ghibli

Offline

#4 2020-08-28 15:11:16

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,401

Re: [SOLVED] Memory Usage more human reader

NICE!!!!


The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

#5 2020-08-28 15:20:28

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 976
Website

Re: [SOLVED] Memory Usage more human reader

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.


OS: Devuan GNU/Linux 4 (chimaera/ceres)
WM: Openbox / Tint2

Studio Ghibli

Offline

#6 2020-08-28 15:48:59

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,401

Re: [SOLVED] Memory Usage more human reader

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%)

The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

#7 2020-08-28 15:50:49

damo
....moderator....
Registered: 2015-08-20
Posts: 6,271

Re: [SOLVED] Memory Usage more human reader

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

#8 2020-08-28 16:14:53

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 976
Website

Re: [SOLVED] Memory Usage more human reader

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 wink


OS: Devuan GNU/Linux 4 (chimaera/ceres)
WM: Openbox / Tint2

Studio Ghibli

Offline

#9 2020-08-28 17:46:28

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,401

Re: [SOLVED] Memory Usage more human reader

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.


The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

#10 2020-08-28 17:56:28

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 976
Website

Re: [SOLVED] Memory Usage more human reader

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 smile


OS: Devuan GNU/Linux 4 (chimaera/ceres)
WM: Openbox / Tint2

Studio Ghibli

Offline

#11 2020-08-28 19:03:19

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,401

Re: [SOLVED] Memory Usage more human reader

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%)

The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

#12 2020-08-28 20:04:39

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 976
Website

Re: [SOLVED] Memory Usage more human reader

Woah! how many choices, S11 you're incredible. I'll save two or three of those.
I'm already overwhelmed wink


OS: Devuan GNU/Linux 4 (chimaera/ceres)
WM: Openbox / Tint2

Studio Ghibli

Offline

#13 2020-08-28 20:30:46

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,401

Re: [SOLVED] Memory Usage more human reader

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.


The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

#14 2020-08-28 20:58:59

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 976
Website

Re: [SOLVED] Memory Usage more human reader

Both of you who offers your help are sincerely thanked. I have very good output memory usages now.


OS: Devuan GNU/Linux 4 (chimaera/ceres)
WM: Openbox / Tint2

Studio Ghibli

Offline

#15 2020-08-28 23:06:17

damo
....moderator....
Registered: 2015-08-20
Posts: 6,271

Re: [SOLVED] Memory Usage more human reader

Nili wrote:

Both of you who offers your help are sincerely thanked....

"And me!", damo squeaked plaintively  tongue


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

#16 2020-08-29 08:19:11

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 976
Website

Re: [SOLVED] Memory Usage more human reader

damo wrote:

"And me!", damo squeaked plaintively  tongue

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.


OS: Devuan GNU/Linux 4 (chimaera/ceres)
WM: Openbox / Tint2

Studio Ghibli

Offline

Board footer

Powered by FluxBB