What is the command to find the RAM size in my computer? I want to see the result in megabytes (MB).
6 Answers
From a terminal you should be able to use:
free -m
From man page:
-m,--mebiDisplay the amount of memory in mebibytes.
--megaDisplay the amount of memory in megabytes. Implies--si.
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
- 1,599
-
29
free -hseems most helpful to me. "all output fields automatically scaled to shortest three digit unit" – craq Aug 04 '19 at 23:19
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.
- 41,690
-
1
lshw -c memoryFTW! run as root in RHEL 7.9 is states each installed ram dimm manufacturer (i.e. samsung) and serial number and dimm slot and clock speed and size in GiB. – ron Apr 15 '21 at 13:58 -
the
sudoforlshwis super important - otherwise you'll NOT get the actual physical state, the command warns you if you don't run it as superuser, but it's easy to overlook :-) – jave.web Dec 12 '21 at 21:37
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.
- 19,518
-
-
2Upvoting for the
grep MemTotal /proc/meminfo, which works great via ssh. – Artif3x Oct 12 '22 at 19:24
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
- 41,378
-
for me (Ubuntu 22), running lshw even without sudo shows *-memory description: System memory physical id: 0 size: 4GiB so although there is a warning at the end of the output that results may not be accurate without sudo, for memory (or for me?) it seems to be ok, and in GiB. – Legolas Dec 10 '24 at 15:33
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
- 370
free -h --siproduces human readable output, in SI units of MB, GB, etc. – Jollywatt Feb 12 '20 at 22:27free -hwill output it in human-readable output (usually GiB: Gibibytes--base 1024). But, since RAM is usually sold in GB (Gigabytes--base 1000), NOT GiB (Gibibytes),free -h --siis usually better, as @Jollywatt says, to output it in Gigabytes instead. – Gabriel Staples Dec 14 '21 at 08:16free --mega(then dividing by 1000 and not rounding down) gives me the closest to what my system monitor tells me.free --megagives15523and the system monitor prints out 15.5 GB. – icc97 May 22 '24 at 15:44