Use a shell script to clean up the memory buffcache

#!/bin/bash
printf "\e[0;32m数据写入硬盘中,请稍等\e[0m\n"

#写入硬盘,防止数据丢失
sync;sync;sync

printf "\e[5;33m正在清理缓存,请稍等\e[0m\n"
sleep 10

echo 3 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 1 > /proc/sys/vm/drop_caches
  • The data to be written to the hard disk in the Linux system is sometimes written to the filesystem buffer for efficiency. This buffer is a memory space. If the data to be written to the hard disk is stored in this buffer, and the system suddenly loses power If so, the data will be lost, and the sync command will force the data stored in the buffer to be written to the hard disk.

Guess you like

Origin blog.csdn.net/u010383467/article/details/112972304