/tmp文件夹和/var/tmp文件夹的定期清理机制

news/2023/11/28 22:47:11


/tmp文件夹和/var/tmp文件夹的定期清理机制

[root@hgdb02 tmp]# ll
total 8
drwxr-xr-x. 5 root root  37 May 19 11:01 benchmarksql-5.0 ---------->>>有此文件
drwxr-xr-x. 2 root root   6 Jun  8 10:10 hsperfdata_root
-rw-------. 1 root root 185 Jun  8 03:38 netdata-updater.log.6xMwv9
-rw-------. 1 root root 185 May 29 03:19 netdata-updater.log.BeFUtt
drwx------. 3 root root  16 Jun 25 15:20 systemd-private-28f9e88904ad483087853f5cade95232-cups.service-2sdeRq

---->>>>过一会,
[root@hgdb02 tmp]# cd ben ---------->>>无此文件
-bash: cd: ben: No such file or directory
[root@hgdb02 tmp]# cd ben*---------->>>无此文件
-bash: cd: ben*: No such file or directory
[root@hgdb02 tmp]# ll     ---------->>>无此文件
total 0
drwx------. 3 root root 16 Jun 25 15:20 systemd-private-28f9e88904ad483087853f5cade95232-cups.service-2sdeRq
[root@hgdb02 tmp]#

我都怀疑这个OS是不是被黑了。。。。

然后查了一下/tmp下是否有定期清理的机制,还真有:
/tmp下的定期清理机制,在6和7下,是不一样的:
Oracle Linux: tmpfiles on Oracle Linux 7 (文档 ID 2273942.1) ---适用于linux 7
On Oracle Linux 7, tmpfiles cleans up /tmp or /var/tmp by removing unused files.
This function was called "tmpwatch" on OL6 which is invoked by crond, however, it is now realized by timer of systemd on OL7.


Files/Directories in /tmp Could be Removed Automatically (文档 ID 2212480.1) ----适用于linux  5和linux 6

如下全文转载Oracle Linux: tmpfiles on Oracle Linux 7 (文档 ID 2273942.1) :

On Oracle Linux 7, tmpfiles cleans up /tmp or /var/tmp by removing unused files.
This function was called "tmpwatch" on OL6 which is invoked by crond, however, it is now realized by timer of systemd on OL7.

 Currently the detailed functions of tmpfiles are described in configuration files:

/usr/lib/systemd/system/systemd-tmpfiles-clean.timer
/usr/lib/systemd/system/systemd-tmpfiles-clean.service
/usr/lib/tmpfiles.d/tmp.conf
 Shortly speaking, the functions are:

removing files/directories in /tmp/ un-accessed more than 10 days(defined in tmp.conf)
removing files/directories in /var/tmp/ un-accessed more than 30 days(defined in tmp.conf)
there are several files which will not be removed(defined in tmp.conf)
the removing command is "/usr/bin/systemd-tmpfiles --clean"(defined in systemd-tmpfiles-clean.service)
 "un-accessed" is decided by checking all of atime/mtime/ctime of the file/directory.
 Thus, in case even one of atime/mtime/ctime of a file in /tmp/ is newer than 10 days, the file will not removed.
 If a file/directory in /tmp/ is not removed by tmpfiles even if it seems it is older than 10 days,
 the reason can be checked by running a command with debug options like below manually:

# SYSTEMD_LOG_TARGET=console SYSTEMD_LOG_LEVEL=debug /usr/bin/systemd-tmpfiles --clean
For example, below intends that a directory "/tmp/abcdefg" can not be removed due to its atime.

# SYSTEMD_LOG_TARGET=console SYSTEMD_LOG_LEVEL=debug /usr/bin/systemd-tmpfiles --clean 2>&1 | grep abcdefg
Directory "/tmp/abcdefg": access time Wed 2017-05-24 16:56:28.771577 JST is too new
#

如下全文转载Files/Directories in /tmp Could be Removed Automatically (文档 ID 2212480.1)
APPLIES TO:
Linux OS - Version Oracle Linux 5.0 to Oracle Linux 6.8 [Release OL5 to OL6U8]
Information in this document applies to any platform.
SYMPTOMS
 If files/directories in /tmp have not been accessed for a long time, they may be removed automatically.

CAUSE
 "tmpwatch" cleans up the contents of /tmp or other temporary directories.

SOLUTION
 In most cases, tmpwatch removing files is safely ignorable as unused files should be removed from /tmp to free up file system space so the file system containing /tmp doesn't fill over time.

 However, if you strongly need to disable this function for some reason, despite the importance of tmpwatch in ensuring /tmp doesn't cause a file system to fill, it is possible by uninstalling tmpwatch:

# rpm -e tmpwatch
or, alternatively, move/remove /etc/cron.daily/tmpwatch file in case the rpm package for tmpwatch can't be removed, such as below:

# rpm -e tmpwatch
LANG=C rpm -e tmpwatch
error: Failed dependencies:
tmpwatch is needed by (installed) tetex-3.0-33.15.el5_8.1.x86_64
tmpwatch is needed by (installed) cups-1.3.7-32.el5_11.x86_64
#
 

Cleaning up unaccessed files in /tmp s a default function of package "tmpwatch", which provides a cron job /etc/cron.daily/tmpwatch. This is a shell script kicked by crond daily,which checks /tmp, /var/tmp and several directories in /var/ and remove files/directories which have not been accessed for a long time.

For example, /etc/cron.daily/tmpwatch on Oracle Linux 5 shows:

flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
        -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
        -X '/tmp/hsperfdata_*' 240 /tmp
/usr/sbin/tmpwatch "$flags" 720 /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
     if [ -d "$d" ]; then
        /usr/sbin/tmpwatch "$flags" -f 720 "$d"
     fi
done
which will remove files/directories that have not been accessed for 240 or 720 hours(=10 or 30 days).

/etc/cron.daily/tmpwatch on Oracle Linux 6 shows:

#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
         -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
         -X '/tmp/hsperfdata_*' -X '/tmp/.hdb*lock' -X '/tmp/.sapstartsrv*.log' \
         -X '/tmp/pymp-*' 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
     if [ -d "$d" ]; then
         /usr/sbin/tmpwatch "$flags" -f 30d "$d"
     fi
done

which will remove files/directories that have not been accessed for 10 or 30 days.

参考文章:

https://developers.redhat.com/blog/2016/09/20/managing-temporary-files-with-systemd-tmpfiles-on-rhel7/


http://www.ppmy.cn/news/785079.html

相关文章

服务器临时文件删除bat,bat|明明白白批量快速删除垃圾文件、不需要的以及临时文件-tmp是什么文件...

图形用户界面的鼠标操作有它的优势所在,其文件系统是逐渐展开的,其操作有直观性。但如果想批量逐级建立n个文件或文件夹,遍历某个路径下全部子文件夹并删除某个类型或文件名中包含特定字符的文件,在图形用户界面下操作就很麻烦&am…

如何删除系统日志和 tmp 目录下的临时文件

文章目录 删除系统日志查看系统日志所占空间删除系统日志 删除临时文件缓存 删除系统日志 查看系统日志所占空间 [userlocalhost ~]$ sudo du --human-readable --max-depth1 /var/log/ [userlocalhost ~]$ sudo journalctl --disk-usage What is: [userlocalhost ~]$ what…

如何删除tmp计算机桌面,技术传授win10 office tmp缓存文件怎么删除的具体处理门径...

可能由于病毒或者木马程序,有一位用户今天来告诉小编说win10 office tmp缓存文件怎么删除的情况和,win10 office tmp缓存文件怎么删除这样的情况还真的把很多电脑高手都为难住了,要是你不愿意找别人来帮助解决你的win10 office tmp缓存文件怎…

关于linux tmp下文件自动删除的问题

事件起源:昨天值班过程中,应用组同事反馈一台linux机器的/tmp目录下自己放的脚本没有了,而且脚本相对挺重要,瞬时冷汗冒出。 作为一名运维工程师最怕删东西,找值班同事及系统组同事确认后,没有人为清理&am…

如何删除tmp计算机桌面,win10系统下tmp临时文件删除不了像何解决

当我们在使用win10系统的途中中,所有会产生很多的临时文件,太多的话就会占用系统磁盘空间影响电脑运列速度,所以就需要删除临时文件,然但是有win10系统用户竟然发现tmp临时文件删除不了,可以怎么解决呢,接着…

如何删除tmp计算机桌面,Win10专业版如何删除tmp文件?

TMP和TEMP文件是各种软件或系统产生的临时文件,也就是常说的垃圾文件,通常会在系统盘下存放,很多win10用户觉得系统盘太多就是因为临时文件太多,但是想删除却提示权限不够,删不了,那要如何解决呢&#xff1…

java--删除TMP文件

实验目的 (1)了解Flie类的概念。 (2)掌握File类的用法。 (3)掌握使用迭代遍历文件夹的方式。 实验内容 (1)了解Java的输入/输出操作。 (2)学会文件与目…

html5 拖拽删除,H5拖拽删除文件

在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放。 全局属性draggable :标签设置draggabletrue后,就能够被拖拽: 单纯地给元素加上draggable属性,也只能在鼠标按住、拖拽、放开时看到特效,它…

58. 批量删除 tmp 文件

文章目录 题目描述解题思路代码详解运行截图题目描述 题目:系统运行一段时间后,会产生大量的tmp文件,会影响系统性能。 实现:做一个批量删除指定文件夹里的tmp文件工具 解题思路 创建一个类:TempDeletionTool 使用TempDeletionTool继承JFrame构建窗体 遍历指定目录下…

h5如何删除手机的目录文件

h5如何删除手机的目录文件 h5中,如何删除手机中存储的文件。 思路: 1、通过plus找到文件夹。 2、递归删除文件夹的文件。 plus.io.resolveLocalFileSystemURL(_doc/, function(entry){ // alert(entry.toLocalURL());entry.removeRecursively( f…

部署 zabbix 自动发现/注册、代理服务器、高可用

目录 一、部署 zabbix 自动发现与自动注册 1.zabbix自动发现与自动注册简介 1.1zabbix 自动发现(对于 agent2 是被动模式) 1.2zabbix 自动注册(对于 agent2 是主动模式) 2.部署 zabbix 自动发现 2.1关闭防火墙 2.2确保客户…

天津大学-23年夏令营上机测试--第1题-字符串压缩

为了更好的阅读体检,可以查看我的算法学习网 在线评测链接:P1321 题目内容 在进行数据传输时常使用字符串压缩算法节约资源,小 C C C发现在他传输的字符串中有很多连续的字符,他基于这一点创造了以下压缩方法: 所有相同且连续的字符串将被…

部分优秀软件概览

产品 产品概览 英特尔相关图书 这些书籍由技术专家撰写,为您呈现多位工程师的心得。我们撰写这些书籍是为了使计算机系统开发人员、集成人员及工程师全面了解英特尔 架构解决方案,并满足他们的相关需求。我们的书籍通常是同类书籍中推出最早的&#xff0…

DSP:数字信号处理(Digital Signal Processing)

目录 数字信号处理 DSP微处理器 轻松体验DSP DSP技术 中国DSP市场现状 DSP未来发展 Windows系统DSP 文件扩展名:DSP 磷酸氢二钠:DSP DSP的应用 DSP的优缺点: 磷酸氢二钠:DSP DSP的应用 DSP的优缺点: [ 编辑本段] 数字…

Three.js粒子特效,shader渲染初探

这大概是个序 关于Three.js,网上有不多不少的零碎教程,有些过于初级,有些云里雾里,而Three.js官网上的示例逼格之高又令人望而却步,这些对于没学过计算机图形学的童鞋来说,就像入门迈槛不知先迈左脚还是右脚…

Oracle11g 64位下载

下载地址 http://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_1of2.ziphttp://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_2of2.zip如果下载出现如下错误页面 这时候可以登录oracle官网,随意点击一个下载&am…

局域网电脑互访的设置大全

1、取消默认的“简单文件共享” 双击我的电脑/工具/文件夹选项/查看,将“使用简单文件共享(推荐)” 前面的√去掉。 2、设置同一工作组 右击我的电脑/计算机名,若工作组相同,如WORKGROUP,则可。否则&am…

工业互联网(十三)——工业相机相关知识(初学者必备)

1.工业相机相关知识(初学者必备) 工业相机是机器视觉系统中的一个关键组件,其最本质的功能就是通过传感器将光信号转变成有序的电信号,通过线缆传输至电脑终端实现图像采集和保存等操作,工业相机在机器视觉系统中处于…

Linux项目:《视频监控》基于正点原子I.MX6ULL_MINI板

前言:本项目更改自韦东山老师的视频监控项目,如果想深入了解该项目,建议去看韦老师的视频。本人只是将其适配成正点原子的Linux板子,如有侵权,请务必告知。必删!谢谢! PC端与手机端通过局域网在…

YOLOV5-Lite轻量化部署与训练

文章目录 前言项目下载项目运行自定义数据集训练使用LabelImg标注制作数据集划分训练文件生成标签聚合操作辅助脚本需要运行的脚本 开始训练 总结 前言 没啥意思,很简单,需要实现一个目标检测,但是,不能占用太多运算资源&#xf…
最新文章