当前位置:首页 > 服务器类 > Linux > 正文内容

Centos7清理/tmp文件夹

Codefans2年前 (2022-01-02)Linux1294

 Centos 6以及6以下的系统使用watchtmp + cron来实现定时清理临时文件的效果,这点在Centos 7发生了变化。


一.  系统自动清理


 在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

可根据个人需求调整清理时间


二.  手动清理


    系统默认情况下每日清理一次tmp目录文件,原理就是使用了tmpwatch。


    首先进行安装:yum install -y tmpwatch


    安装成功后,执行清理任务:tmpwatch 24 /tmp/    #删除/tmp目录下超过24小时未使用的文件,最小为1小时。

扫描二维码推送至手机访问。

版权声明:本文由图慧网发布,如需转载请注明出处。

本文链接:http://www.tuh8.com/index.php?mod=article&act=view&id=25

分享给朋友:

“Centos7清理/tmp文件夹” 的相关文章

Ubuntu开机自动挂载硬盘ntfs分区

sudo mkdir /media/Esudo chmod -R 777 /media/E获取要自动挂载的分区的UUID和分区类型TYPEsudo blkid /dev/sda3: UUID=”000F70A100099B09″ TYPE=”ntfs” 试一下,看看能否挂载到 /...

Ubuntu下几种格式的安装包安装方法

1. .deb格式双击打开直接安装。在新版本ubuntu中由于移除啦ubuntu软件中心,并替换成Gnome软件(又改名为ubuntu软件),导致无法直接安装,可使用下面的命令安装(假设安装包位于/home/a1eafall)$sudo dpkg -i /home/a1...

Ubuntu搜狗输入法安装指南

Ubuntu搜狗输入法安装指南

Ubuntu搜狗输入法安装指南搜狗输入法已支持Ubuntu1604、1804、1910、2004、2010各系统安装步骤可能略有不同,以Ubuntu2004为例。1、添加中文语言支持打开 系统设置——区域和语言——管理已安装的语言——在“语言”tab下——点击“添加或删除语言”弹出“已安装语言”窗口...

ubuntu格式化硬盘

(1)查看硬盘sudo fdisk -lu或sudo blkid(2)格式化磁盘 sudo mkfs.ext4 /dev/sdb (3)将格式化后的磁盘 挂载在8t目录下sudo mount /dev/sdb  ~/8t(4)修改/etc/fstab 添加开机自动挂载s...

Linux Docker systemctl 命令无法使用的解决方案

问题介绍:在 Ubuntu 20.04 的 Docker 容器中无法使用 systemctl 命令众所周知 systemctl 可以用来启动、停止服务和查询服务状态的。例如你可以使用 systemctl start apache2 这条命令来启动 Apache 服务。使用 systemctl 命令时...

详解 docker save 与 docker export 的区别

详解 docker save 与 docker export 的区别

缘起docker save和docker export都能导出镜像包,咋看起来区别似乎不大。本文就针对这个问题,试图搞清楚docker save和docker export的功能是什么?适用于什么应用场景?本文的测试的Docker版本如下,不保证所有版本的docker都能重现本文的结果。&...