15
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Amazon linux 2] /tmp配下の自動削除

Posted at

/tmp配下ファイル削除の仕組み

  • /tmp配下ファイルの削除タイミングは、systemdのtimerで指定されています。
  • systemd-tmpfiles-clean.timerの中身を確認することで、そのタイミングを知ることができます。(デフォルト: 起動後 15 分経過時点と、それ以降に一日置きにタイマーが発火)
$ sudo systemctl cat systemd-tmpfiles-clean.timer
 ...
 [Timer]
 OnBootSec=15min
 OnUnitActiveSec=1d
  • タイマーが発火後は、以下のコマンドが実行されます。
$ sudo systemctl cat systemd-tmpfiles-clean.service
...
ExecStart=/usr/bin/systemd-tmpfiles --clean
  • --clean オプションを指定していると、 systemd-tmpfiles.d の設定ファイルで Age パラメータでした期間を経過したファイルが削除されます。

  • 削除対象のファイルは、/usr/lib/tmpfiles.d/tmp.confで指定されています。
    /usr/lib/tmpfiles.d/tmp.confのファイルの中を確認すると、デフォルトで/tmpは10日、/var/tmpは30日で配下のファイルが削除される設定が書かれています。


$ cat /usr/lib/tmpfiles.d/tmp.conf
...
# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d
...

次回及び前回のタイマー発火時刻の確認方法

  • Amazon linux2だと、systemd list-timersコマンドで確認できます。
sh-4.2$ sudo systemctl list-timers
15
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?