Welcome to todays tech article! We're covering emptying buffers and cache in Linux, so let's just get into it.
Linux has a command you can use called echo which will clear the cache for you without interrupting any processes. This command has three functions and can be executed like so (from root).
# echo 1 > /proc/sys/vm/drop_caches
Clear dentries and inodes:
# sync; echo 2 > /proc/sys/vm/drop_caches
Clear pagecache, dentries, and inodes:
# sync; echo 3 > /proc/sys/vm/drop_caches
The sync command in this code is used to clear the system buffer, while the echo command will execute after the sync finishes.
Again, these are all root level commands. The sudo version changes the syntax a bit, like so:
$ sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches'
The echo command works the exact same way, and you can substitute a 2 or 3 in that command to get the result you want.
Well the real answer is that you usually shouldn't unless you're running tests ir benchmarks. Linux will automatically use your available ram for disk caching. Clearing this cache out will make your pc run slower, while providing no other benefit. So there's really no reason to clear cache or buffers unless you're testing something specifically.
That's it for today's article! If you have questions about it, any feedback on ServerSuit or just keep up with our updates, follow and @ us on Facebook and Twitter.
Until Next Time!