When you order a dedicated server or cloud server with your web hosting provider, there is one thing you must check always when you first login into your system: your hardware must be exactly the same as ordered.
Lot of times, because of order mistakes, dedicated servers providers will give you less hardware resources than the ones you purchased. On this post, we will find out how to find RAM size in Linux / Unix operating systems with 5 useful commands.
How can I Find RAM size in Linux operating systems?
Here is the list of the top 5 commands that can be used to find LInux RAM size in Linux.
1. free command
The free command is the most classic terminal based tool to check memory usage on Linux / Unix operating systems.
[[email protected]:~]free total used free shared buff/cache available Mem: 32753636 9492448 1053688 603920 22207500 21961040 Swap: 8191996 1078724 7113272 [[email protected]:~]
The total OS RAM in bytes is 32753636, which can be translated to 32 GB of RAM installed on the system. The second colum called ‘used’ shows the the RAM used by the operating system, in this case around 9GB. Then you have the Free colum that is showing around 1GB, and the others called ‘shared’, ‘buffer/cache’ and ‘available’. It is normal to see lot of cached memory in the buff/cache on Linux operating systems, this memory can later be freed and used if really needed.
The last line belongs to the swap memory, which is reporting around 1GB of usage.
But this byte based numbers are not easy to read. Let’s use two useful parameters that can be added to the free command:
free -ht
Now we add -ht to the free command. -h is used to transform bytes into human readable units, and -t is used to display a line showing the column totals.
[[email protected]:~]free -ht total used free shared buff/cache available Mem: 31G 9.1G 1.0G 589M 21G 20G Swap: 7.8G 1.0G 6.8G Total: 39G 10G 7.8G [[email protected]:~]
As you see on this output, now the free command is showing the information in sizes humans can read.
2. top command
Top command is one of my favourite and most used tools to quickly check out system performance, but it can also be used to get valuable hardware information.
As you see on the screenshot, top command shows the total memory usage on an option called: KiB Mem (32753636 total in my case).
You will also be able to get your SWAP size, on the other line called KiB Swap (8191996 total in my case).
And same as the free command, you will get other kind of RAM information like buffer, cache and free available memory.
3. htop
htop is a good alternative to the classic top command, apart from RAM information, you will be able to get CPU and process usage. In clear words, htop is the top command but with an improved version which include colors, bar graphs for CPU/Mem/Swap, and a better way to deal/kill processes if needed.
Installing htop on Ubuntu/Debian
apt-get install htop
Installing htop on CentOS/RHEL
yum install htop -y
htop can be run simply by running:
htop
Expected output:
As you see, the available RAM and SWAP usage is pretty clear, showed in GBs and with a clear bar.
4. vmstat
vmstat command along with the “s” parameter with show you memory uisage statistics, from there you will also be able to get total RAM memory and free memory.
Run this command:
vmstat -s
This is an output example on our server:
[[email protected]:~]vmstat -s 32753636 K total memory 9562108 K used memory 11811520 K active memory 16346200 K inactive memory 927968 K free memory 0 K buffer memory 22263560 K swap cache 8191996 K total swap 1078724 K used swap 7113272 K free swap 70588049 non-nice user cpu ticks 4283838 nice user cpu ticks 24577630 system cpu ticks 2023074528 idle cpu ticks 4177230 IO-wait cpu ticks 0 IRQ cpu ticks 1063579 softirq cpu ticks 0 stolen cpu ticks 3076934802 pages paged in 6491214798 pages paged out 620025 pages swapped in 1033879 pages swapped out 4238671160 interrupts 3149823550 CPU context switches 1490028842 boot time 10854442 forks [[email protected]:~]
5. cat /proc/meminfo
The last way to find RAM size in Linux is by reading the /proc/meminfo file. For this we will use cat command, as you see below:
cat /proc/meminfo
Expected output:
Find Hardware RAM Information
If you need to find out your full hardware information about the RAM you are using on your server, you can use the dmidecode command. It will show you valuable information about the installed RAM memory on your system.
Install dmidecode on Ubuntu/Debian
apt-get install dmidecode
Install dmidecode on CentOS/RHEL
yum install dmidecode -y
Now run this command:
dmidecode -t 17 | more
You will be able to get total RAM size, type (DDR2, DDR3, DDR4) and RAM speed, among other things, as you see on this screenshot of the nixcp.com server:
Further reading: