Home > Package & System Management > systemd-tmpfiles

systemd-tmpfiles: Managing Temporary and Volatile Files

`systemd-tmpfiles` is a utility used to create, delete, and clean up temporary files, volatile files, and runtime directories on a system. It operates based on configuration files such as those found in `/etc/tmpfiles.d/*.conf` and `/usr/lib/tmpfiles.d/*.conf`. It runs during system boot or periodically to manage the state of the file system, contributing to system stability and security.

Overview

`systemd-tmpfiles` is a `systemd` utility for managing temporary files and runtime directories on a system. It creates, deletes, and modifies permissions of files and directories according to rules defined in configuration files. It is typically executed during boot via `systemd-tmpfiles-setup.service` or periodically by `systemd-tmpfiles-clean.timer`.

Key Features

  • Automated file/directory management based on configuration files
  • Creation and initialization of necessary temporary directories during boot
  • Periodic cleanup of old temporary files and directories
  • Setting file ownership, permissions, and SELinux contexts

Key Options

`systemd-tmpfiles` can control file management operations through various options.

Command Modes

Other Options

Generated command:

Try combining the commands.

Description:

`systemd-tmpfiles` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Common usage examples for `systemd-tmpfiles`.

Create temporary files and directories based on configuration

sudo systemd-tmpfiles --create

Creates files and directories according to the rules defined in all `tmpfiles.d` configuration files on the system. This is similar to the task automatically performed by `systemd-tmpfiles-setup.service` during boot.

Clean up old temporary files and directories

sudo systemd-tmpfiles --clean

Deletes old temporary files and directories based on the 'age' rules specified in the configuration files. This is periodically executed by `systemd-tmpfiles-clean.timer`.

Simulate creation operations without actual changes

sudo systemd-tmpfiles --create --dry-run

Shows what operations would be performed by the `--create` command without actually creating or modifying any files. Useful for previewing changes before critical operations.

Run cleanup operation in debug mode

sudo systemd-tmpfiles --clean --debug

Executes the cleanup operation for old files in debug mode to view detailed logs. This is helpful for diagnosing issues.

Tips & Notes

`systemd-tmpfiles` manages critical system directories, so caution is advised when modifying configuration files.

Configuration File Locations

`systemd-tmpfiles` reads configuration files from the following paths. Files in directories with lower numbers have higher precedence.

  • /etc/tmpfiles.d/*.conf: User-defined and system administrator configurations
  • /run/tmpfiles.d/*.conf: Temporary configurations generated at runtime
  • /usr/lib/tmpfiles.d/*.conf: Default configurations provided by packages

Configuration File Format

Each line in a configuration file typically follows the format: `type path mode uid gid age argument`. Fields are space-separated, and comments start with `#`.

Key Type Characters

Common type characters used in configuration files.

  • d: Create directory
  • f: Create file
  • L: Create symbolic link
  • x: Exclude path (from cleanup)
  • r: Remove path (during cleanup)
  • z: Set SELinux context for path

Caution

Incorrect `tmpfiles.d` configurations can lead to system instability or loss of important data. It is highly recommended to back up configuration files before making changes and to use the `--dry-run` option to preview modifications.



Same category commands