tmp目录的下的备份文件定期删除

本文介绍Centos/RHEL/Fedora系统中使用tmpwatch工具自动清理/tmp目录下长时间未被访问的文件的方法。通过定时任务配置,系统可以定期删除10天以上未访问的临时文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Centos/RHEL/Fedora系统完全安装,系统存在清理机制,会定时清理/tmp目录下文件

Centos/RHEL/Fedora系统最小化安装没有该机制


用到工具:tmpwatch

yum install tmpwatch -y

包含以下文件:

/etc/cron.daily/tmpwatch
/usr/bin/tmpwatch
/usr/sbin/tmpwatch
/usr/share/doc/tmpwatch-2.9.16
/usr/share/doc/tmpwatch-2.9.16/COPYING
/usr/share/doc/tmpwatch-2.9.16/ChangeLog
/usr/share/doc/tmpwatch-2.9.16/NEWS
/usr/share/doc/tmpwatch-2.9.16/README
/usr/share/man/man8/tmpwatch.8.gz

tmpwatch命令的作用就是删除一段时间内不使用的文件
安装后会在/etc/cron.daily/目录下生成一个tmpwatch文件。内容如下:

[root@LAMP linuxuser]# ls /etc/cron.daily/
logrotate  makewhatis.cron  mlocate.cron  tmpwatch

1
2
3
4
5
6
7
8
9
10
11
12
#! /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 in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
    if [ -d "$d" ]; then
        /usr/sbin/tmpwatch "$flags" -f 30d "$d"
    fi
done

从脚本中可看出,tmp目录会删除10天未访问过的文件。


本文转自 boy461205160 51CTO博客,原文链接:http://blog.51cto.com/461205160/1929646


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值