Centos7清理/tmp文件夾

 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

可根據個人需求調整清理時間,具體可參考 http://blog.51cto.com/kusorz/2051877?utm_source=oschina-app

二.  手動清理

    系統默認情況下每日清理一次tmp目錄文件,原理就是使用了tmpwatch。

    首先進行安裝:yum install -y tmpwatch

    安裝成功後,執行清理任務:tmpwatch 24 /tmp/    #刪除/tmp目錄下超過24小時未使用的文件,最小爲1小時。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章