• Welcome to LiuJason's Blog!

CentOS下安全的清理/tmp路径下的临时文件

Linux笔记 Jason 1 years ago (2019-04-12) 401 Views 0 Comments QR code of this page

1. 系统自动清理
在Centos 7下,系统使用systemd管理易变与临时文件,/tmp目录的清理规则主要取决于/usr/lib/tmpfiles.d/tmp.conf文件的设定,默认的配置内容为:

# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d # 清理/tmp下10天前的目录和文件
v /var/tmp 1777 root root 30d # 清理/var/tmp下30天前的目录和文件

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp

2. 手动清理
注意!不能简单的rm -rf /tmp/*
这样会导致正在使用的临时文件被删除,出现一系列问题
正确的做法:
yum install -y tmpwatch
#删除24小时内未使用的临时文件
tmpwatch 24 /tmp/


This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/263.html
Like (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址