Linux / tmp下的文件和文件夹清理

耶尔

在我所有的Red Hat Linux机器7.2版上,我们都看到systemd-tmpfiles-clean.service是不活动的:

systemctl status systemd-tmpfiles-clean.service
● systemd-tmpfiles-clean.service - Cleanup of Temporary Directories
   Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-clean.service; static; vendor preset: disabled)
   Active: inactive (dead) since Wed 2018-12-19 14:47:14 UTC; 12min ago
     Docs: man:tmpfiles.d(5)
           man:systemd-tmpfiles(8)
  Process: 34231 ExecStart=/usr/bin/systemd-tmpfiles --clean (code=exited, status=0/SUCCESS)
 Main PID: 34231 (code=exited, status=0/SUCCESS)

Dec 19 14:47:14 master02.uridns.com systemd[1]: Starting Cleanup of Temporary Directories...
Dec 19 14:47:14 master02.uridns.com systemd[1]: Started Cleanup of Temporary Directories.

奇怪的是,我们在下看到了文件和文件夹/tmp,并且似乎每隔一段时间执行一次清理。

我搜索了crontab或cronjob,但没有找到其他清理作业。

我在这里想念什么吗?

尽管服务处于不活动状态,是否有可能每两周执行一次清理?

  systemctl enable  systemd-tmpfiles-clean.service

The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).

我们还看到了一些真正的旧文件夹,例如

ls -ltr
total 137452
drwxr-xr-x 3 root      root         33 Jun 13  2017 Tools
drwx--x--x 3 root      root         16 Oct 12 09:33 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-httpd.service-QZqGLA
drwx--x--x 3 root      root         16 Oct 12 10:02 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-rtkit-daemon.service-BTcGY1
drwx--x--x 3 root      root         16 Oct 12 10:02 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-vmtoolsd.service-mQ1SXc
drwxr-xr-x 2 ambari    ambari       18 Oct 12 12:02 hsperfdata_ambari
drwx--x--x 3 root      root         16 Oct 12 12:17 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-cups.service-PnKaq8
drwx--x--x 3 root      root         16 Oct 12 12:17 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-colord.service-DNn470
-rwxr-xr-x 1 root      root      83044 Nov 18 17:27 Spark_Thrift.log
drwxr-xr-x 2 zookeeper hadoop       18 Nov 18 17:28 hsperfdata_zookeeper
-rwxr-xr-x 1 root      root        379 Nov 18 17:37 requests.txt
-rwxr-xr-x 1 root      root     137348 Nov 22 14:50 pp
-rwxr-xr-x 1 root      root        344 Nov 26 15:24 yy
prwx--x--x 1 root      root          0 Nov 29 21:26 hogsuspend
-rwxr-xr-x 1 root      root       1032 Dec  3 10:55 aa

在我的机器上:

more /lib/systemd/system/systemd-tmpfiles-clean.timer
#  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.

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

[Timer]
OnBootSec=15min
OnUnitActiveSec=1d

规则是:

more /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
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
斯蒂芬·基特

您可以询问systemd单位的触发器是什么:

systemctl show -p TriggeredBy systemd-tmpfiles-clean

这将表明该systemd-tmpfiles-clean服务是由systemd-tmpfiles-clean.timer计时器触发的定义为

#  SPDX-License-Identifier: LGPL-2.1+
#
#  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.

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

[Timer]
OnBootSec=15min
OnUnitActiveSec=1d

因此,该服务每天运行,并根据tmpfiles.d配置清理目录有关详细信息,请参见相关的手册页。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Linux上安全清理tmp文件夹

来自分类Dev

Linux文件夹和文件权限

来自分类Dev

Linux open()系统调用和文件夹权限

来自分类Dev

在C中以递归方式打印Linux路径中的所有文件和文件夹

来自分类Dev

在多个目录中创建和复制文件和文件夹的Linux命令

来自分类Dev

如何查找最近在Linux中删除了哪些文件和文件夹?

来自分类Dev

为Linux中的新文件夹和文件设置默认权限

来自分类Dev

统计Linux服务器上的och文件夹和文件结构

来自分类Dev

Linux-如何为用户提供对主文件夹和文件的完全访问权限?

来自分类Dev

在Linux bash中复制具有完整路径的文件和文件夹

来自分类Dev

Linux根据名称长度查找文件和文件夹但输出完整路径

来自分类Dev

Linux“下载”文件夹

来自分类Dev

Linux链接文件夹

来自分类Dev

Bash脚本清理Linux服务器会话文件夹

来自分类Dev

如何以pythonic方式操作/清理Linux Trash文件夹?

来自分类Dev

Linux文件/文件夹权限

来自分类Dev

Linux /文件夹和/ root文件夹

来自分类Dev

Linux Shell文件夹中的Zip文件夹

来自分类Dev

递归bash脚本,用于在Mac / Linux上使用特定规则重命名文件和文件夹

来自分类Dev

您可以像在Linux上一样在MacOS上隐藏文件和文件夹吗?

来自分类Dev

linux下使用python通过终端统计文件夹中所有文件的行数

来自分类Dev

将Linux根文件夹的子文件夹(/ tmp,/ lib,/ etc)移动到另一个位置会影响系统吗?

来自分类Dev

在Linux中移动文件夹

来自分类Dev

在Linux中更改.eclipse文件夹

来自分类Dev

在Linux分区上移动文件夹

来自分类Dev

用完软件的Linux Downloads文件夹?

来自分类Dev

在Linux中移动文件夹

来自分类Dev

Linux文件夹的复制范围

来自分类Dev

linux合并文件夹:rsync?

Related 相关文章

  1. 1

    如何在Linux上安全清理tmp文件夹

  2. 2

    Linux文件夹和文件权限

  3. 3

    Linux open()系统调用和文件夹权限

  4. 4

    在C中以递归方式打印Linux路径中的所有文件和文件夹

  5. 5

    在多个目录中创建和复制文件和文件夹的Linux命令

  6. 6

    如何查找最近在Linux中删除了哪些文件和文件夹?

  7. 7

    为Linux中的新文件夹和文件设置默认权限

  8. 8

    统计Linux服务器上的och文件夹和文件结构

  9. 9

    Linux-如何为用户提供对主文件夹和文件的完全访问权限?

  10. 10

    在Linux bash中复制具有完整路径的文件和文件夹

  11. 11

    Linux根据名称长度查找文件和文件夹但输出完整路径

  12. 12

    Linux“下载”文件夹

  13. 13

    Linux链接文件夹

  14. 14

    Bash脚本清理Linux服务器会话文件夹

  15. 15

    如何以pythonic方式操作/清理Linux Trash文件夹?

  16. 16

    Linux文件/文件夹权限

  17. 17

    Linux /文件夹和/ root文件夹

  18. 18

    Linux Shell文件夹中的Zip文件夹

  19. 19

    递归bash脚本,用于在Mac / Linux上使用特定规则重命名文件和文件夹

  20. 20

    您可以像在Linux上一样在MacOS上隐藏文件和文件夹吗?

  21. 21

    linux下使用python通过终端统计文件夹中所有文件的行数

  22. 22

    将Linux根文件夹的子文件夹(/ tmp,/ lib,/ etc)移动到另一个位置会影响系统吗?

  23. 23

    在Linux中移动文件夹

  24. 24

    在Linux中更改.eclipse文件夹

  25. 25

    在Linux分区上移动文件夹

  26. 26

    用完软件的Linux Downloads文件夹?

  27. 27

    在Linux中移动文件夹

  28. 28

    Linux文件夹的复制范围

  29. 29

    linux合并文件夹:rsync?

热门标签

归档