systemd-tmpfiles
Create, delete, and clean temporary files
TLDR
Create files and directories as specified in the configuration
Clean up files and directories with age parameters configured
Remove files and directories as specified in the configuration
Apply operations for user-specific configurations
Execute lines marked for early boot
SYNOPSIS
systemd-tmpfiles [OPTIONS...] [CONFIG_FILE...]
systemd-tmpfiles {--create|--clean|--remove} [OPTIONS...]
systemd-tmpfiles --cat-config [CONFIG_FILE...]
PARAMETERS
--create
Creates and applies ownership/permissions to runtime directories and files as specified in configuration files. This is typically run at boot.
--clean
Cleans up old files and directories based on age settings in configuration files. This is typically run periodically.
--remove
Removes all files and directories specified in the configuration files, regardless of age. Use with caution.
--boot
An alias for --create --remove --apply-mode --tmpfs-size. This option is typically used by systemd-tmpfiles-setup.service at boot.
--prefix=PATH
Only process configuration lines that affect files or directories under the specified PATH.
--user
Operate on user-specific temporary directories and configuration files (e.g., ~/.config/tmpfiles.d/).
--root=PATH
Operate on a specified alternate root directory instead of the host's root. Useful for chroot/container environments.
--cat-config
Prints the parsed content of the configuration files to standard output.
--force
Overrides certain protections, such as removing non-empty directories without an explicit r+ type. Use with extreme care.
--verbose
Show more detailed output during execution.
--quiet
Suppress most output, only show errors.
--help
Display a help message and exit.
--version
Show version information and exit.
DESCRIPTION
systemd-tmpfiles is a utility that creates, deletes, and cleans up volatile and temporary files and directories, typically located in paths like /run, /tmp, and /var/tmp.
It reads configuration from various files (e.g., /etc/tmpfiles.d/*.conf, /run/tmpfiles.d/*.conf, /usr/lib/tmpfiles.d/*.conf) to apply predefined rules. These rules specify how directories should be created (with correct permissions and ownership), how files should be handled (e.g., creating specific files or symlinks), and how old files and directories should be pruned.
The primary goal is to ensure the integrity and cleanliness of these crucial system paths, which are often cleared on reboot or periodically. It's an integral part of systemd, automating tasks that were traditionally handled by various ad-hoc scripts, improving reliability and consistency in temporary file management.
CAVEATS
Misconfiguring systemd-tmpfiles can lead to unexpected data loss, particularly with the --remove or --force options, or security vulnerabilities if permissions are set incorrectly. Always back up critical configurations and test changes in a non-production environment. Most operations require root privileges.
CONFIGURATION FILES
systemd-tmpfiles reads configuration from files ending with .conf in the following directories, processed in order of precedence: /etc/tmpfiles.d/ (local overrides), /run/tmpfiles.d/ (runtime configuration), and /usr/lib/tmpfiles.d/ (vendor-supplied defaults). Files later in the processing order or in higher-priority directories can override earlier entries.
SERVICE INTEGRATION
On a typical systemd system, systemd-tmpfiles is invoked by two main services: systemd-tmpfiles-setup.service which runs at boot (using --boot) to create and set up initial permissions for volatile directories, and systemd-tmpfiles-clean.service which runs periodically (using --clean) to prune old temporary files based on age settings.
HISTORY
systemd-tmpfiles was introduced as part of the systemd initialization system to provide a centralized and declarative method for managing volatile and temporary file system paths. Before systemd, these tasks were often handled by a collection of disparate shell scripts (e.g., in /etc/rc.d or /etc/init.d), which varied significantly across distributions and versions.
Its development aimed to standardize the cleanup and setup of critical runtime directories like /run, /tmp, and /var/tmp, ensuring consistent behavior, proper permissions, and timely cleanup, thereby enhancing system stability and security.