<img alt="Check swap space in Linux" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/check-swap-space-in-linux-1024×512.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="375" src="data:image/svg xml,” width=”750″>

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

In this article, we will describe a few ways to check for available swap space on your Ubuntu system. The commands and procedures described in this article have been run on an Ubuntu 20.04 LTS system.

We are making use of the Ubuntu command line, the Terminal, in order to check swap space on our system. In order to open the Terminal, you can either use the Dash or the Ctrl alt T shortcut. Then you can choose the following ways to get swap space information:

The Linux free command

Command:

$ free

This command is used to check memory and swap utilization on your system in a few lines. Without the use of any switch, the displayed output is printed in kilobytes.

<img alt="Check swap space with free command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-233.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="136" loading="lazy" src="data:image/svg xml,” width=”734″>

Command:

$ free -h

With the -h switch, the free command displays the memory and swap utilization in nearest possible, 3 digit format.

<img alt="free -h command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-234.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="77" loading="lazy" src="data:image/svg xml,” width=”733″>

The swapon command

Command:

$ swapon -s

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

<img alt="The swapon command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-235.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="90" loading="lazy" src="data:image/svg xml,” width=”732″>Advertisement

The top command

Command:

$ top

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

<img alt="Check swap usage with top command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-236.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="171" loading="lazy" src="data:image/svg xml,” width=”728″>

The vmstat command

Command:

$ vmstat

Through the vmstat command, you can view the swap in and swap out information. However, you can not see the total values of the swap as seen is the previously mentioned commands.

<img alt="Use vmstat command to check swap space" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-237.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="95" loading="lazy" src="data:image/svg xml,” width=”741″>

The /proc/swaps file

Command:

$ cat /proc/swaps

You can also view the swap size information through the swap configuration file /proc/swaps. It also displays device-wise swap information so that you can see device name (partition, logical volume or file), its type and how much swap it contributing to the system.

<img alt="Check content of /proc/swaps" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-238.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="87" loading="lazy" src="data:image/svg xml,” width=”736″>

Though the very simple commands described in this article, you can view the swap space on your Ubuntu system and utilize it when your system is running low on RAM resources.