Finding the free and used memory with the free command

  • Post author:
  • Post last modified:November 14, 2024
  • Reading time:3 mins read

Using the free command, the free and used memory in a Linux or Unix system can be found. The free command can be given from the command line as,

free

And the system responds with an output like,

             total    used     free  shared  buffers  cached
Mem:        960268  873136    87132       0    14652  168884
-/+ buffers/cache:  689600   270668
Swap:      2996116   95332  2900784

In the above output, the system has 960,268 kilobytes of total memory, which is less than the actual physical memory because the memory occupied by the kernel is not reported here. Of the total memory of 960,268 kilobytes, 873,136k is used and the rest is free. The shared memory column is obsolete and should be ignored. Next, we have 14,652k I/O buffers and a page cache usage of 168,884k (Total page cache is cached (168,884k) and Swap cached, which is not reported by free, but is available in the underlying /proc/meminfo). Since the buffers and cached are released as processes demand more memory in the system, the free memory is more than what is shown in the third column of the first line under free (87,132k, here). The free memory is free memory shown in the first line (87,132k) plus buffers (14,652k) plus cached (168,884k). The total of these three figures is 270,668k, which is the actual free memory and is shown under the column free in the next line of output. The rest of the memory (960,268k – 270,668k), 689,600k is the actual memory used and is reported under used in the -/+ buffers/cache line. The last line gives the amount of total swap memory on the disk, swap used and the free swap memory.

Command Line Options

The command line syntax is,

free [-b|-k|-m|-g] [-c count] [-l] [-o] [-t] [-s delay] [-V]

The command line options are,

free – Command Line Options
Option Description
-s delay print output continuously, delay seconds apart
-c count quit after count iterations. Requires -s option
-b report the memory in bytes
-k report the memory in kilobytes (default)
-m report the memory in megabytes
-g report the memory in gigabytes
-l display detailed low and high memory statistics
-o display in the old format, -/+ buffers/cache line is not displayed
-t display column totals
-V display the version information

Reference

Karunesh Johri

Software developer, working with C and Linux.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments