5 commands to check swap space on Linux

When the physical memory or RAM in our system is full, we end up using the swap space in our systems. In this process, inactive pages of our memory are moved to the swap space, creating more memory resources. This space is especially useful when the system is not working in RAM; however, the swap space is located on the hard drive and, therefore, access to it is slower. Therefore, it should not be considered a suitable alternative to RAM.

In this article, we will describe several ways to check the available swap space on your Ubuntu system. The commands and procedures described in this article ran on the Ubuntu 18.04 LTS system.

We use the Ubuntu, Terminal command line to check the swap space on our system. To open the Terminal, you can use the Dash or Ctrl + alt + T key combination. Then you can choose the following ways to get information about the swap space:

Linux Free Team

Command:

$ free

This command is used to check memory usage and swap on your system for several lines. Without using any switch, the displayed output is printed in kilobytes.

Check swap space with a free command

Command:

$ free -h

With the -h switch, the free command displays memory and swap usage in the nearest three-digit format.

free -h team

Swapon team

Command:

$ swapon -s

You can use the swapon command to check swap on a specific partition, logical volume, or file. Here we will use it with the -s (summary) switch to get swap information (in kilobytes).

Swapon team

Top team

Command:

$ top

The header section of the output of the top command shows information about the paging space in kilobytes. Other commands that provide this information include htop, glances, itop, etc.

Check swap usage with the top command

Vmstat team

Command:

$ vmstat

Using the vmstat command, you can view information about paging and uploading. However, you cannot see the general swap values, as seen from the previously mentioned commands.

Use vmstat command to check paging space

File / proc / swaps

Command:

$ cat /proc/swaps

You can also view swap size information through the swap configuration file / proc / swaps. It also displays information about swapping the device, so you can see the name of the device (partition, logical volume or file), its type and the amount of swap that contributes to the system.

Check the contents of / proc / swaps

Despite the very simple commands described in this article, you can view the swap space on your Ubuntu system and use it when your system does not have enough RAM resources.

5 commands to check swap space on Linux

Sidebar