Linux : how to read output parse from “free” command

for example :

[myapit@linuxserver ~]$ free -m
             total  used  free  shared  buffers  cached
Mem:         7872   7732  139   0       1478     4346
-/+ buffers/cache:  1907  5964
Swap:        4095   45    4050

from the output above, we can get :-

First Line :

  • 7872 – total physical RAM size
  • 7732 – total RAM used include buffers and cached
  • 139 – total free RAM to be used by new process
  • 0 – shared memory, obsolete (not use anymore)
  • 1478 – total RAM buffered by applications
  • 4346 – total RAM used as cached by applications

Second Line:

-/+ buffers/cache:  1907  5964

What is the difference between buffers and Cache?
A buffer is a temporary location to store data for a particular application and this data is not used by any other application. This is similar to bandwidth concept. When you try to send burst of data through network, if your network card is capable of sending less data, it will keep these huge amounts of data in buffer so that it can send data constantly in lesser speeds. In other hand Cache is a memory location to store frequently used data for faster access. Other difference between a buffer and a cache is that cache can be used multiple times where as buffer is used single time. And both are temporary store for your data processing.


Third Line: -linux swap
Swap:        4095   45    4050

:: calculation to get the actual used and free ram
 Used RAM = 7732 - from first line
 Used Buffer = 1478 - from first line
 Used Cached = 4346 - from first line
Actual total used RAM = 7732 - (1478+4346) = 1908
Total available RAM = 7872 - 1908 = 5964

based on calculation above, in my opinion, we can use information from Second Line to get the actual used and free ram as the value after calculation seems to be the same




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s