300

What is the command to find the RAM size in my computer? I want to see the result in megabytes (MB).

melvio
  • 370
KonradDos
  • 3,281

6 Answers6

311

From a terminal you should be able to use:

free -m

From man page:

-m, --mebi Display the amount of memory in mebibytes.

--mega Display the amount of memory in megabytes. Implies --si.

Note: A kilobyte (kB) is 1000 Bytes.

FCTW
  • 3,281
151

Open a terminal (CTRL + ALT + T)...

Run following command to see RAM information in KB (1 KB is equal to 1024 bytes).

free

Run following command to see RAM information in MB (1 MB is equal to 1024 KB).

free -m

Run following command to see RAM information in GB (1 GB is equal to 1024 MB).

free -g

Or you can run following command to see more information about the same:

free -h
Victor
  • 1,589
  • 1
  • 8
  • 3
58

Click on the power/gear icon (System Menu) in the top right corner of the screen and choose About This Computer. You will see the total available memory in GiB. Multiply the value by 1024 to get the size in MiB.

This value (and the value shown as Total in output of free -m on the console), is total physical RAM size, minus the amount assigned to the internal GPU, if your computer has one.

To see the total amount of physical RAM installed, you can run sudo lshw -c memory which will show you each individual bank of RAM you have installed, as well as the total size for the System Memory. This will likely presented as GiB value, which you can again multiply by 1024 to get the MiB value.

dobey
  • 41,650
45

Physical memory available in MiB:

echo $(($(getconf _PHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024)))

Virtual memory available in MB:

echo $(($(getconf _AVPHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024)))

..or use /proc/meminfo:

grep MemTotal /proc/meminfo | awk '{print $2 / 1024}'

To see the physical chip information, you can use dmidecode to extract the DMI type 17 (Memory Device) tagged information:

sudo dmidecode -t 17

this informs you about all the memory devices installed, including the type, speed, manufacturer, form factor and a lot more besides. Yo also have sudo dmidecode -t memory which give a little bit more information.

3

What seems to be missing here is a method to display the actual physical memory.

free doesn't display the actual physical memory. From man free under total:

Total usable memory (MemTotal and SwapTotal in /proc/meminfo). This includes the physical and swap memory minus a few reserved bits and kernel binary code.

% LANG=C free -b
               total        used        free      shared  buff/cache   available
Mem:     33208266752  4826804224 25715757056   609566720  3756187648 28381462528
Swap:     8589930496           0  8589930496
% printf '33208266752\n' | numfmt --to=iec --format '%0.8f'
30,92760849G

Which is not the 32GiB I paid for.

To fix that, you can use lshw to extract the actual physical memory in bytes and pass the output to numfmt (the --format '%.8f' is there just to show that I'm not cheating and that there's no rounding happening under the hood):

sudo lshw -json 2>/dev/null |
    jq -r '.children[] | select(.id=="core").children[] | select(.id=="memory").size' |
    numfmt --to=iec --format '%.8f'
% sudo lshw -json 2>/dev/null |
    jq -r '.children[] | select(.id=="core").children[] | select(.id=="memory").size' |
    numfmt --to=iec --format '%.8f'
32,00000000G

This will display the actual physical memory using the IEC standard (which is the one typically used by vendors to label / market DIMMs - 16GiB, 32GiB, 64GiB and so on) - so you can rest peacefully knowing the vendor didn't slice some memory off your bank(s).

If you want to display the actual physical memory using the SI standard:

sudo lshw -json 2>/dev/null |
    jq -r '.children[] | select(.id=="core").children[] | select(.id=="memory").size' |
    numfmt --to=si --format '%.8f'
% sudo lshw -json 2>/dev/null |
    jq -r '.children[] | select(.id=="core").children[] | select(.id=="memory").size' |
    numfmt --to=si --format '%.8f'
34,35973837G
kos
  • 41,268
2

If you want a command to just output the numeric value of total memory in MB, you can use:

free --mega | awk '/^Mem:/{print $2}'

This number represents the total RAM installed in the system in MB, for example:

free --mega | awk '/^Mem:/{print $2}'
33033
melvio
  • 370