본문 바로가기

OS/Linux, Unix

/tmp 디렉토리 자동 삭제 기능

Temporary Directory Cleanup 서비스

  • Red Hat Enterprise Linux 7.0 이상에서 새롭게 추가된 기본 서비스

  • /tmp , /var/tmp 디렉토리 파일 및 하위 디렉토리를 주기적으로 삭제하는 기능을 제공

 

Temporary Directory Cleanup 서비스 중지

systemctl stop systemd-tmpfiles-clean.timer

 

Temporary Directory Cleanup 서비스 관련 정보

설정 파일

  • /usr/lib/tmpfiles.d/tmp.conf

    • 삭제 대상 디렉토리 및 기간 (/tmp 디렉토리의 경우 10일이상 변경되지 않은 파일 및 디렉토리에 대하여 삭제)

      • x 옵션 : 등록한 디렉토리의 내용이 모두 제외(디렉토리, 파일 모두 삭제 안 함)
      • X 옵션 : 등록한 디렉토리만 제외, 등록한 디렉토리 안의 내용은 삭제(디렉토리는 남기고, 파일만 삭제)
cat /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 7d
v /var/tmp 1777 root root 30d
 
# 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

 

  • /usr/lib/systemd/system/systemd-tmpfiles-clean.timer

    • 해당 서비스의 동작 주기

cat /usr/lib/systemd/system/systemd-tmpfiles-clean.timer

[Unit]
Description=Daily Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)

[Timer]
OnBootSec=15min				# 시스템 부팅 15분 후 구동
OnUnitActiveSec=1d			# 매 1일 주기로 해당 시간에 동작

 

'OS > Linux, Unix' 카테고리의 다른 글

smartctl 로 HDD 점검  (0) 2020.11.01
IPMI  (0) 2020.11.01
CPU, DISK, MEMORY 확인 명령어  (0) 2020.10.31
NTP  (0) 2020.10.31
local.repo 만드는 법  (0) 2020.10.31