DEV Community

Iyadchafroud
Iyadchafroud

Posted on • Updated on

Clear Cache for lunix

we can use The free command is used to display amount of free and used memory in the system. The command also displays the total amount of swap memory in the system and buffers and caches used by the Linux kernel.

free -m

Enter fullscreen mode Exit fullscreen mode

and to Clear memory we can use :
To clear pagecache only:

sync; echo 1 > /proc/sys/vm/drop_caches

Enter fullscreen mode Exit fullscreen mode

To clear dentries and inodes:

sync; echo 2 > /proc/sys/vm/drop_caches

Enter fullscreen mode Exit fullscreen mode

To clear pagecache, dentries and inodes:

sync; echo 3 > /proc/sys/vm/drop_caches

Enter fullscreen mode Exit fullscreen mode

to empty buffer and cache:

free && sync && echo 3 > /proc/sys/vm/drop_caches && free
Enter fullscreen mode Exit fullscreen mode

if you has this probleme of permission
bash: /proc/sys/vm/drop_caches: Permission denied

you can use echo piped to sudo tee to allow the proper permission needed when you need to echo as root

echo 3 | sudo tee /proc/sys/vm/drop_caches
Enter fullscreen mode Exit fullscreen mode

Top comments (0)