Linux Commands

How to Check Swap Memory in Linux

Are you reaching maximum usage of your swap memory? Stuck? How to see swap memory in your Linux system? You just landed at the right place to get unstuck. I am going to discuss some better and perfect new ways of observing swap memory for you. I’m using Lubuntu 20.04 to demonstrate all these processes. Lubuntu is a lightweight distro and runs effectively on most of the hardware.
Let’s begin.

Using GUI – The Simplest Way Possible

I always use the following two ways to determine existing swap memory on my system. I also want to let you know that I use SSDs; therefore, I do not need to configure swap memory. This is entirely a different discussion that why I don’t need to swap memory. However, all the instructions and commands discussed here will lead to checking and keeping swap memory not running out.

Using hTop

I use Htop to look into my system processes. It is utterly simple and gorgeous in looks because it uses quite a little of the RAM and shoots into the shell once launched. Below is the screenshot of hTop in action.

hTop is simple to use and can be installed right straight with the following command:

sudo apt install htop

If you ever need to remove hTop, just run below command:

sudo apt remove htop

The given command will make sure that everything is removed. In my case, I do not use any swap; therefore, it is 0K/0K. Neither it flows in nor out.

Using qps

The second GUI tool, qps, also has its benefits. Although it doesn’t run in a shell and takes its own memory space, it is very simple to use. In the screenshot below, I show you how simple it is. I have launched it via the terminal to make the launch process a bit geekier. However, you can simply launch it from your start menu. As already discussed, it won’t show any swap memory in my case as I am not using it. The program can be installed using the below command:

sudo apt install qps

Whereas, uninstall process is also similar:

sudo apt remove qps

All commands are valid for Debian and related distros that make use of .deb repositories.

Using Command Line Interface

Our geekier and simpler way to do anything in Linux is to get it done via command line. Here, I’ll share and demonstrate to you a few commands. Here is the simplest command out there in the Linux world.

free -h

The command free -h is handy when you want to see how much your swap memory is in total and how much it is in use.

Another command to check availability and consumed swap memory is to look into /proc/meminfo files.

Here is how to read the related file:

cat /proc/meminfo | grep -i swap

The given command will grab the total, free, and cached swap memory and display it on the terminal.

Fantastic! Isn’t it?

Conclusion

We discussed how to nail swap memory and make the best use of it. I used no swap on my Lubuntu distro, and all the commands and programs clearly showed that not a single bit is flowing throughout the system.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.