28 C
Texas
angeloma
Senior Writer and partner

How to clear cache on any distribution Linux?

Hello, friends. In this very short post, we will show you how to clear the cache in Linux. This tutorial, although it will be done in Ubuntu, will work in any distribution that has systemd.

Linux is an operating system that manages memory very well and that’s why the cache exists. Every time we open a file or directory they are temporarily stored in the main memory to make them accessible and speed up the system. However, there are situations in which it is required to clean the cache to free more space in it.

So it can be done from the terminal without any problem. Let’s see.

Clear cache on any Linux distribution

The first thing to know is that in Linux there are several types of cache.

- Advertisement -

On the one hand, there is the PageCache that refers to files and programs that are stored in RAM and do not need to be reloaded from the hard disk.

On the other hand, there is Dentry and inode cache which are the attributes of these files.

So let’s get to the point.

First, execute the free command with the -h argument so that you notice how the RAM is being used.

free -h

In my case the screen output gives the following data:

total used free shared buff/cache available
Mem: 3,7G 2,2G 145M 242M 1,3G 934M
Swap: 964M 11M 953M

As you can see my computer has little RAM and the cache takes a good part.

If you want to clean it up, just execute the following command:

sudo sysctl vm.drop_caches=3

This command will remove all the cache, but you can also just remove the PageCache, by running

sudo sysctl vm.drop_caches=1

Or just the inodes:

sudo sysctl vm.drop_caches=2

In any case, if you execute the free command again you will be able to notice the results.

free -h

So, congratulations, you completed the tutorial and you know how to clear cache on Linux.

Conclusion

Generally, you will probably never feel the need to go through this process, but it is good to know so that you can use it when necessary.

Finally, remember that cleaning the cache can slow down the system at first, but it can be used in specific cases.

So, share this post and join our Telegram channel and our Facebook page. Also, buy us a coffee 😉

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article