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

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文件。内容如下:

[[email protected] linuxuser]# ls /etc/cron.daily/
logrotate  makewhatis.cron  mlocate.cron  tmpwatch

#! /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

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

时间: 2024-08-29 23:11:25

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

老男孩教育每日一题-2017年5月24日-脑洞神探之tmp目录的下的备份文件突然没了,谁来背锅?

1.题目 2.参考答案 1.运维干的2.开发干的3.系统干的,系统安装了一个命令tmpwatch,定期删除文件. 在Centos/RHEL/Fedora系统下存在清理机制(Ubuntu下没有,我的系统是CentOS6)yum -y install tmpwatchtmpwatch命令的作用就是删除一段时间内不使用的文件安装后会在/etc/cron.daily/目录下生成一个tmpwatch文件.内容如下: #! /bin/sh flags=-umc /usr/sbin/tmpwatch "$fl

复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的 行首的空白字符及在vim中设置tab缩进为4个字符

1.复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的 行首的空白字符 在命令模式下,使用正则表达式匹配 行首有空白字符行的模式:^[[:space:]]*\([^[:space:]]*\),输出命令 %s#^[[:space:]]*\([^[:space:]]*\)#\1#g1 2.vim中设置tab缩进为4个字符 vim .vimrc 输入 set tabstop=4 原文地址:https://www.cnblogs.com/mwd-123/p/

Azure Automation (2) 定期删除存储账号中的文件

<Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China. 本文是对笔者之前的文档Azure Backup (1) 将SQL Server 2012虚拟机中数据库备份到Azure Storage进行的补充. 希望笔者先阅读Azure Automation (1) 入门,对Azure Automation有基本的概念认识. 需求: 在之前的文档中Azure Backup (1) 将SQL Server 2012虚拟机中数据库备份到Az

Linux下tmp目录删除规则

我们知道,在Linux系统中/tmp文件夹里面的文件会被清空,至于多长时间被清空,如何清空的,可能大家知识的就不多了,所以,今天我们就来剖析一个这两个问题. 在RHEL\CentOS\Fedora\系统中(本次实验是在RHEL6中进行的) 先来看看tmpwatch这个命令,他的作用就是删除一段时间内不使用的文件(removes files which haven't been accessed for a period of time).具体的用法就不多说了,有兴趣的自行研究.我们主要看看和这个

Linux下关于/tmp目录的清理规则

本文将介绍Linux下/tmp目录的清理规则,rhel6和rhel7将以完全不同的两种方式进行清理. RHEL6 tmpwatch命令 tmpwatch 是专门用于解决"删除 xxx天没有被访问/修改过的文件"这样需求的命令. 安装: [[email protected] ~]# yum install tmpwatch.x86_64 使用: man tmpwatch tmpwatch - removes files which haven't been accessed for a

Debian下自动备份文件并上传到远程FTP服务器且删除指定日期前的备份Shell脚本

说明:  1.备份目录/home/osyunwei下面所有的文件到/home/osyunweibak里面,并且保存为osyunwei20120701.tar.gz的压缩文件格式(2012_07_01是指备份执行时当天的日期),最后只保留最近7天的备份 2.上传/home/osyunweibak里面的备份文件到远程FTP服务器上,并且只保留最近7天的备份. 3.FTP服务器:192.168.21.139 端口:21 账号:osyunwei 密码:123456 osyunweibak为备份文件存放目

linux 下/var,/etc,/tmp目录操作

显示/var/目录下所有以1开头,以一个小写字母结尾,且中间至少出现一位数字(可以有其他字符)的文件或目录. 命令: ls -d /var/1*[0-9]*[a-z] 显示/etc目录下,以任意一个数字开头,且以非数字结尾的文件或目录. 命令: ls -d /etc/[[:digit:]]*[[1]] 显示/etc目录下,亦非字母开头,后面跟了一个字母以及其他任意长度任意字符的文件或目录. 命令: ls -d /etc/[[2]][[:alpha:]]* 在/tem目录下创建以tfile开头,后

CentOS7下/tmp目录里面的文件默认保留多久

早上有同事问了下CentOS7下/tmp目录下文件目录保留多久,我记得CentOS6下默认好像是30天,CentOS7下不太确认,所以查了下: [[email protected] tmpfiles.d]# cd /usr/lib/tmpfiles.d/ [[email protected] tmpfiles.d]# ls abrt.conf                 iscsi.conf           net-snmp.conf         rpcbind.conf      

复制/etc/profile至/tmp/目录用查找替换命令删除/tmp/profile文件中的空白行

复制/etc/profile至/tmp/目录[[email protected] tmp]#cp /etc/profile /tmp删除/tmp/profile文件中的空白行用查找替换命令删除/tmp/profile文件中的行首的空白字符sed '[email protected]^[[:space:]][email protected]@' profile执行前:执行后:[[email protected] tmp]#sed '[email protected]^[[space:]]\[ema