systemd-tmpfiles is a systemd subsystem that creates, deletes, and cleans up temporary files and directories on a system. Its main functions are:
- Create system directories such as
- Cleanup operations on specific directories such as in
Directory cleanups are done using a
systemd-tmpfiles-clean timer and service. On Red Hat based systems, the cleanup timer runs once 15 minutes after startup and also once a day.
Configuration[edit | edit source]
To see the current configs, run:
systemd-tmpfiles --cat-config. Configuration files are located in the following directories:
- Default system config files are located in
- Custom configs can be placed in
/etc/tmpfiles.d. Overrides files with the same names in the other locations listed above.
Custom config[edit | edit source]
See the tmpfiles.d man page for a comprehensive overview. I will go over some important bits below.
To add your own configuration, place a file with a
.conf file extention in
/etc/tmpfiles.d/. Each line should contain a single directive for a single path. For example:
#Type Path Mode UID GID Age Argument d /run/user 0755 root root 10d - L /tmp/foobar - - - - /dev/null
Types that you may frequently use are listed below:
||Create a file if it doesn't exist|
||Create a file or truncate it if it exists|
||Create a directory|
||Create a character device node|
||Removes a file or directory if it exists. Does not follow symlinks. Use 'R' for recursive removes.|
||Exclude a path during a clean operation|
||Exclude a path (to a directory) during a clean operation|
||Creates a subvolume (or directory if the underlying filesystem doesn't support volumes)|
||Creates a symlink|
||Exclamation mark '!' denotes that the rule should only execute on system startup.|
If an age is specified, automatic cleanup of files older than the specified age will be done. Files older than the specified age will be deleted.