How to read total RAM in GBs?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read total RAM in GBs?
# 1  
Old 11-14-2018
How to read total RAM in GBs?

I am aware of the commands to find the total RAM on Linux and Unix for example vmstat.

Can you please tell me which tool / command can give me the Total RAM reading in GBs [gigabytes] on Solaris Unix and Linux ?
# 2  
Old 11-14-2018
Quote:
Originally Posted by mohtashims
I am aware of the commands to find the total RAM on Linux and Unix for example vmstat.

Can you please tell me which tool / command can give me the Total RAM reading in GBs [gigabytes] on Solaris Unix and Linux ?
There is a tool on Linux called numfmt:
Code:
$ wc -c < myfile | numfmt --to=iec
34M

Unfortunately it is not on Solaris to my knowledge. It is, however, part of the Gnu coreutils, so it may be possible to compile it from source.

Andrew
# 3  
Old 11-14-2018
For good precision use awk.
Most handy is a shell function
Code:
kb_to_iec(){
awk '{
 if ($1<1024) {scale=1; unit="K"} else
 if ($1<1048576) {scale=1024; unit="M"} else
 if ($1<1073741824) {scale=1048576; unit="G"} else
 if ($1<1099511627776) {scale=1073741824; unit="T"} else
  {scale=1099511627776; unit="P"}
 printf "%.1f%s\n",$1/scale,unit
}'
}

Code:
echo 1023 | kb_to_iec
1023.0K
echo 1024 | kb_to_iec
1.0M

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Total RAM not recognised

Hi We have a redhat 4 with 8GB ram in it but free -m only recognises 3 GB of total ram please could some one help me why this happens HP syetems insight manager showing 4* 2 GB RAMS # free -m total used free shared buffers cached Mem: 3290... (6 Replies)
Discussion started by: robo
6 Replies

2. Shell Programming and Scripting

Help with sum total number of record and total number of record problem asking

Input file SFSQW 5192.56 HNRNPK 611.486 QEQW 1202.15 ASDR 568.627 QWET 6382.11 SFSQW 4386.3 HNRNPK 100 SFSQW 500 Desired output file SFSQW 10078.86 3 QWET 6382.11 1 QEQW 1202.15 1 HNRNPK 711.49 2 ASDR 568.63 1 The way I tried: (2 Replies)
Discussion started by: patrick87
2 Replies

3. Emergency UNIX and Linux Support

Grab total page read from webalizer display in html

Hi, I need a way to grab the total combines since inception, total pages read from webalizer on my centos server or any other location (as long as since inception) and display the result live on my website So with each visit it would be increasing, or perhaps live (ajax) not sure But can... (0 Replies)
Discussion started by: lawstudent
0 Replies

4. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

5. Red Hat

red hat Linux 5.0 is detecting 3gb ram but physical ram is 16gb

Hi, On server 64bit Hw Arch , Linux 5.0(32bit) is installed it is showing only 3gb of ram though physical is 16gb can u give me idea why? (4 Replies)
Discussion started by: manoj.solaris
4 Replies

6. Shell Programming and Scripting

View the Server Total Ram in GB

Hello, I want to view server RAM in GB i.e 4 GB or 6 GB via command line to use it in bash script waiting Any Ideas :) Thanks :):) (2 Replies)
Discussion started by: LinuxCommandos
2 Replies

7. UNIX for Dummies Questions & Answers

grep running total/ final total across multiple files

Ok, another fun hiccup in my UNIX learning curve. I am trying to count the number of occurrences of an IP address across multiple files named example.hits. I can extract the number of occurrences from the files individually but when you use grep -c with multiple files you get the output similar to... (5 Replies)
Discussion started by: MrAd
5 Replies

8. HP-UX

How should I know the total RAM available on UNIX

Hi How Should I know the Total RAM available on HP-UX box? (7 Replies)
Discussion started by: skull123
7 Replies

9. UNIX for Dummies Questions & Answers

Total ram

Hi How can i find the total ram in the system? :confused: (4 Replies)
Discussion started by: orca
4 Replies
Login or Register to Ask a Question