What are systemd-tmpfiles configuration files?

QuestionsQuestions8 SkillsProDec, 13 2025
0490

You're drilling down into a very good detail there! systemd-tmpfiles is indeed the modern approach for cleaning /tmp and other temporary directories.

systemd-tmpfiles configuration files are simple text files that describe how systemd should handle various temporary, volatile, and transient files and directories at boot, during runtime, and during system cleanups.

Here's a breakdown of what they are and their significance:

  1. Purpose:

    • Create directories/files: They can specify directories and files to be created (e.g., ensuring a specific temporary folder exists with correct permissions).
    • Set permissions/ownership: Define the permissions, ownership, and SELinux contexts for these files/directories.
    • Clean up old files: Most importantly for our discussion, they specify which files/directories should be deleted or emptied based on their age (e.g., "delete everything in /tmp older than 10 days").
  2. Location:

    • These configuration files are typically found in:
      • /usr/lib/tmpfiles.d/: For configuration snippets provided by installed packages. These are usually not meant to be modified by users.
      • /etc/tmpfiles.d/: For local configuration overrides or custom rules created by administrators.
      • /run/tmpfiles.d/: For dynamic or runtime configuration.
    • Files usually have a .conf extension (e.g., tmp.conf, apache.conf).
  3. Syntax:

    • They consist of lines, where each line defines a specific action.
    • Each line starts with a type letter (e.g., d for directory, f for file, r for remove, Z for recursively set permissions, C for copy if missing) followed by arguments like path, mode, UID, GID, age, and argument.

    Example (Simplified):

    # Type  Path                           Mode  UID    GID    Age     Argument
    d       /tmp                           1777  root   root   10d     -
    
    • d: Create a directory if it doesn't exist.
    • /tmp: The path to the directory.
    • 1777: Permissions (sticky bit set, meaning users can delete only their own files).
    • root: Owner (user).
    • root: Group.
    • 10d: Age for cleanup. This is the crucial part for /tmp cleaning. It means files/directories older than 10 days in /tmp will be removed by systemd-tmpfiles. If set to 0 or - it implies no age-based cleanup for this entry, but other rules might still apply.
    • -: Argument (often ignored for directories).
  4. How they are used for cleaning /tmp:

    • When your system boots, systemd reads these configuration files. It uses them to ensure that directories like /tmp (and others) are set up correctly with the right permissions and ownership.
    • More importantly, a systemd service called systemd-tmpfiles-clean.service runs periodically (e.g., daily, or based on specific timers) to perform the actual cleanup operation based on the Age parameter specified in these configuration files. This is how old files in /tmp get deleted automatically.

So, in essence, these .conf files are recipes for systemd to manage the lifecycle of temporary files and directories, ensuring system hygiene and proper operation.

Do you want to see an example of inspecting one of these files on your LabEx VM?

0 Comments

no data
Be the first to share your comment!