In today’s article, we’ll chec memory usage with the free command. We’ve touched on the ‘free’ command before, but this is a whole article about the free command. This should be a pretty quick and easy article, as it’s not a complex command.
There have been a few other articles about RAM.
How To: Find The RAM Total In The Terminal
Check Your Memory In The Terminal: Part II
Let’s Determine The Number of RAM Slots Without Opening The Case
And, in the discussions of those articles, we often refer to
free -m as our go-to tool for quickly checking memory usage. It’s a handy tool used by most, and it’s a good tool to have in your toolbox. On top of that, it does a bit more than just check memory usage.
The free command has been around forever and describes itself like this:
Display amount of free and used memory in the system
Which is exactly what it does. It’s a pretty useful command if you want to see how much RAM you’re using, how much is free, how much is reserved for buffers, and even more if you’re interested in your swap stats.
So, folks are generally already familiar with the free command, but there are indeed more options and it’s worth an article to explain a few of those choices. Like always, you can also run
man free to get a bunch of information that may not be included in this fairly brief article.
Check Memory Usage:
Yeah, this is yet another article that insists on the terminal. That’s not a bad thing, if you check the byline. The goal here at Linux-Tips is to get you more comfortable with Linux – and that includes getting comfortable in the terminal. So, open one up by pressing
With that done, let’s go ahead and try the command that everyone uses:
The output from that will look a little something like this:
You can see by the column titles what the columns mean. Like I said, it’s relatively easy to understand – which is why it makes a pretty great tool. There’s actually a pretty good description of those terms, if you don’t already know them, in the man page.
But, you can use it in other ways. See, the -m stands for megabytes (obviously). Well, you can use other flags, like -b, -k, and -g. That’s bytes, kilobytes, and gigabytes – where the -m is megabytes as previously mentioned.
If you want a nice human-readable format, you can try this:
The output of that may vary the units but it will also show you which units are in use. It’s a pretty handy way to use the free command to check memory usage in Linux.
Sure, there’s a wide format and you can even use units as large as pebibytes. I don’t actually have anything where that’d make sense, but it’s an option if you happen to have such a system. (If you have access to a system with pebibytes of RAM, call me!)
But, did you know that you can run the command over and over again with just a single command? To do that, you use the -s flag followed by the number of seconds you want it to wait before refreshing. So, if you want it to run every 10 seconds, the command would look like this:
free -s 10
You can combine that with a count – like how many times you want it to run. So, something like this:
free -s 5 -c 3
That will run the free command (you could add other modifiers) every five seconds and will do so three times in a row.
There are other options, but those are the most common. You can have it output the low and high numbers (when run over a period of time), display column totals, and even opt for a wider display. Personally, I don’t really find those options all that interesting and don’t bother with them, but they’re a man page away from being a part of your toolbox.
And there you have it, an article teaching you how to check memory usage with the free command. The free tool is a pretty handy tool and one everyone should be familiar with. If your system is slowing down, it’s nice to know things like how much RAM is being used. If you work in application development, it’s nice to know how much more RAM your application adds to the system. There are any number of reasons why you’d want this information.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.