linux清理buffer缓存脚本
1、清理缓存脚本
[root@host-172-21-210-62 opt]# more cleanCache.sh #!/bin/bash #每24小时清除一次缓存 echo "开始清除缓存" sync;sync;sync #写入硬盘,防止数据丢失 sleep 10 #延迟10秒 echo 1 > /proc/sys/vm/drop_caches echo 2 > /proc/sys/vm/drop_caches echo 3 > /proc/sys/vm/drop_caches
2、清理前buff情况
[root@host-172-21-210-62 ~]# free -g total used free shared buff/cache available Mem: 31 4 6 1 19 24 Swap: 0 0 0
3、清理buff
[root@host-172-21-210-62 opt]# sh cleanCache.sh
4、清理后缓存情况
[root@host-172-21-210-62 opt]# free -g total used free shared buff/cache available Mem: 31 4 23 1 2 24 Swap: 0 0 0
drop_caches的详细文档如下:
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. To free pagecache: echo 1 > /proc/sys/vm/drop_caches To free dentries and inodes: echo 2 > /proc/sys/vm/drop_caches To free pagecache, dentries and inodes: echo 3 > /proc/sys/vm/drop_caches As this is a non-destructive operation, and dirty objects are notfreeable, the user should run “sync” first in order to make sure allcached objects are freed. This tunable was added in 2.6.16.
做一个决定,并不难,难的是付诸行动,并且坚持到底。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)