If you are new to Linux you might be wondering how you can find out how much free memory your system has or how your memory is being used. For this there are two simple to use applications: top and free. The top application informs you what tasks are running and how much memory and? CPU? is being used by each. The free application tells you how much total RAM is being consumed by your system. Both are command line applications and both do an outstanding job of reporting information.
Naturally both commands have gui front ends (gnome-system-monitor does both), but what do you do when you have a headless server? Or what about when you are logging in remotely and you can't tunnel X? In those instances you will want to be able to get this information via the command line. And Linux has the tools for you.
The free command displays the amount of free and used physical and swap memory on your system. Free has a limited number of switches to use which makes the command even simpler to use. The switches are:
-b Displays the output in bytes
-k Displays the output in kilobytes (this is the default action)
-t Adds a line at the bottom which contains the totals
-m Displays the output in megabytes
And that's it.
When you run free the output will look like:
total ? ? ? used ? ?? free ?? shared ? buffers? cached
Mem: ? ? ? ??? 884 ? ?? ? 862??????? 22???????? 0?????? 289 ? ? 127
-/+ buffers/cache: ? ? ?? 445 ? ? ? 439
Swap: ? ????? 3992 ? ? ? ?? 0 ? ?? 3992
So you can see the total (in megabytes) memory being 884 and the free being 22. Depending upon your setup and what you have running you might think free is wrong. One thing you have to keep in mind is the buffers and cached memory are actually still available so in the above example the total used memory does include both the buffer and the cached memory. So often there is more memory available for application use than you would think. This gets very confusing because the used memory listing includes memory used by the kernel that may or may not be used for various modules (such as networking, sound, etc). There is another issue confusing memory usage. Since a vast number of Linux applications share libraries (like libc) those libraries could already be in memory when you launch an application. Huh? Let's try a simple explanation.
You have Application A and Application B that both use Library 1. Application A reports it uses 25 MB of memory to run and Application uses 25 MB of memory to run. But Library 1 takes up 5 MB of memory to run. If Application A is already running that means Library 1 is already running so you can subtract the Library memory from the total of Application B.
So you can see how complex memory usage is for Linux. Which is why you want to also check out the command top.
The top command diplays running Linux tasks. The information it offers is:
So you can see there is plenty of information to be had from top. The point is, between the two applications you can summize the amount of memory being used at any given time.
Gnome System Monitor
As I said earlier, there are gui tools for this tasks. One of those tasks is gnome-system-monitor. It gives you every bit of information you need, and does so in a much more easy to use/read format. When you open up this tool you will see, after a bit of poking around, it gets its information with a little help from both free and top. Take a look at this application to see just how well the information is used and displayed.
The image to the left highlights the resource listing tab of gnome-system-monitor.
It's pretty easy to see how complex monitoring memory can be with Linux. Fortunately there are plenty of tools to aid in you in this task. Although it's not always easy to get a cut and dry snapshot of what memory you have available, you can get good idea of where your memory is.
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.