What are the ways to get ram size in Linux operating system?

Here is some methods to find ram size in Linux operating systems like Ubuntu, Debian, Fedora, CentOS, Red Hat.

Getting Ram Size With meminfo

Proc file system provides coonfiguration information about the current opoerating system. We can get information from direcly kernel provided /proc/meminfo . We can see a lot of information parameter with meminfo

$cat /proc/meminfo MemTotal: 1016756 kB MemFree: 159240 kB MemAvailable: 417356 kB Buffers: 868 kB Cached: 362436 kB SwapCached: 0 kB Active: 433572 kB Inactive: 306476 kB Active(anon): 377436 kB Inactive(anon): 7756 kB Active(file): 56136 kB Inactive(file): 298720 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 0 kB SwapFree: 0 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 376776 kB Mapped: 101996 kB Shmem: 8448 kB Slab: 53196 kB SReclaimable: 31768 kB SUnreclaim: 21428 kB KernelStack: 5104 kB PageTables: 22476 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 508376 kB Committed_AS: 2269324 kB VmallocTotal: 34359738367 kB VmallocUsed: 143472 kB VmallocChunk: 34359591920 kB HardwareCorrupted: 0 kB AnonHugePages: 145408 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 59236 kB DirectMap2M: 989184 kB DirectMap1G: 0 kB

As we see there is a lot of details. Actually a lot of monitoring applications gets data from here.

MemTotal is total ram size

Get Ram Size With Simple free Command

We can get ram size with simple free command.

$free total used free shared buff/cache available Mem: 1016756 441008 159324 8448 416424 417416 Swap: 0 0 0

But this will give information with kilobyte size. We want to get megabyte

$free -m total used free shared buff/cache available Mem: 992 430 155 8 406 407 Swap: 0 0 0

Or I think gigabyte is better

$ free -g total used free shared buff/cache available Mem: 15 11 0 1 3 2 Swap: 0 0 0

Getting Ram Size With vmstat

Another tool is vmstat as you see below

$vmstat -s | grep "total memory" 1016756 K total memory

How To Get Ram Size In Linux? Infografic