free memory linux code example

Example 1: linux memory cache clear

# clear pagecache only.
sync; 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

Example 2: clear ram linux

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

Example 3: linux how to free memory

echo 2 > /proc/sys/vm/drop_caches

Example 4: check vm ram details in linux

sudo dmidecode -t 17

Example 5: free memory linux command

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