free utility shows the amount of free and used memory in a system. The output is similar to the memory information displayed by top.
Memory data is often misinterpreted. The main source of confusion is related to buffers and caching. Keeping data in memory speeds things up, and the Linux kernel therefore uses as much memory as possible for caching. However, this memory can be released at any time. For instance, if a processes asks for a big chunk of memory then the kernel can simply give it some of the cached memory. So, memory used for caching is both used and available. I have described this in more detail in my article about memory data in free and top.
Let’s look at an example. The below output shows that the system has 797M of free memory. However, some of that memory is used for caching. The actual amount of available memory is therefore higher (1.1G):
$ free -h total used free shared buff/cache available Mem: 1.8G 503M 797M 39M 537M 1.1G Swap: 3.9G 899M 3.0G
The same is not true for swap memory. A swap partition (or file) never uses caching – data either is or isn’t written to the file system. So, in the case of swap the free column does reflect how much memory is free.
free shows the following information:
free displays amounts in kibibytes. You can use the
–g option to use mebibytes or gibibytes instead.
Another useful option is
--human). As the name suggests, this option makes the stats “human readable”. Columns will use mebibytes or gibibytes, depending on which unit is the easiest to interpret by humans.
And finally, the
-t option adds a row with the grand totals:
$ free -ht
total used free shared buff/cache available
Mem: 1.8G 494M 767M 41M 576M 1.1G
Swap: 3.9G 897M 3.0G
Total: 5.7G 1.4G 3.8G