]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/tmpfiles.d.xml
Merge pull request #23309 from DaanDeMeyer/log-context
[thirdparty/systemd.git] / man / tmpfiles.d.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!--
5 SPDX-License-Identifier: LGPL-2.1-or-later
6
7 Copyright © 2010 Brandon Philips
8 -->
9 <refentry id="tmpfiles.d"
10 xmlns:xi="http://www.w3.org/2001/XInclude">
11
12 <refentryinfo>
13 <title>tmpfiles.d</title>
14 <productname>systemd</productname>
15 </refentryinfo>
16
17 <refmeta>
18 <refentrytitle>tmpfiles.d</refentrytitle>
19 <manvolnum>5</manvolnum>
20 </refmeta>
21
22 <refnamediv>
23 <refname>tmpfiles.d</refname>
24 <refpurpose>Configuration for creation, deletion and cleaning of
25 volatile and temporary files</refpurpose>
26 </refnamediv>
27
28 <refsynopsisdiv>
29 <para><literallayout><filename>/etc/tmpfiles.d/*.conf</filename>
30 <filename>/run/tmpfiles.d/*.conf</filename>
31 <filename>/usr/lib/tmpfiles.d/*.conf</filename>
32 </literallayout></para>
33
34 <para><literallayout><filename>~/.config/user-tmpfiles.d/*.conf</filename>
35 <filename>$XDG_RUNTIME_DIR/user-tmpfiles.d/*.conf</filename>
36 <filename>~/.local/share/user-tmpfiles.d/*.conf</filename>
37 <filename index='false'></filename>
38 <filename>/usr/share/user-tmpfiles.d/*.conf</filename>
39 </literallayout></para>
40
41 <programlisting>#Type Path Mode User Group Age Argument
42 f /file/to/create mode user group - content
43 f+ /file/to/create-or-truncate mode user group - content
44 w /file/to/write-to - - - - content
45 w+ /file/to/append-to - - - - content
46 d /directory/to/create-and-cleanup mode user group cleanup-age -
47 D /directory/to/create-and-remove mode user group cleanup-age -
48 e /directory/to/cleanup mode user group cleanup-age -
49 v /subvolume-or-directory/to/create mode user group cleanup-age -
50 q /subvolume-or-directory/to/create mode user group cleanup-age -
51 Q /subvolume-or-directory/to/create mode user group cleanup-age -
52 p /fifo/to/create mode user group - -
53 p+ /fifo/to/[re]create mode user group - -
54 L /symlink/to/create - - - - symlink/target/path
55 L+ /symlink/to/[re]create - - - - symlink/target/path
56 c /dev/char-device-to-create mode user group - major:minor
57 c+ /dev/char-device-to-[re]create mode user group - major:minor
58 b /dev/block-device-to-create mode user group - major:minor
59 b+ /dev/block-device-to-[re]create mode user group - major:minor
60 C /target/to/create - - - cleanup-age /source/to/copy
61 x /path-or-glob/to/ignore/recursively - - - cleanup-age -
62 X /path-or-glob/to/ignore - - - cleanup-age -
63 r /empty/dir/to/remove - - - - -
64 R /dir/to/remove/recursively - - - - -
65 z /path-or-glob/to/adjust/mode mode user group - -
66 Z /path-or-glob/to/adjust/mode/recursively mode user group - -
67 t /path-or-glob/to/set/xattrs - - - - xattrs
68 T /path-or-glob/to/set/xattrs/recursively - - - - xattrs
69 h /path-or-glob/to/set/attrs - - - - file attrs
70 H /path-or-glob/to/set/attrs/recursively - - - - file attrs
71 a /path-or-glob/to/set/acls - - - - POSIX ACLs
72 a+ /path-or-glob/to/append/acls - - - - POSIX ACLs
73 A /path-or-glob/to/set/acls/recursively - - - - POSIX ACLs
74 A+ /path-or-glob/to/append/acls/recursively - - - - POSIX ACLs
75
76 </programlisting>
77 </refsynopsisdiv>
78
79 <refsect1>
80 <title>Description</title>
81
82 <para><filename>tmpfiles.d</filename> configuration files provide a generic mechanism to define the
83 <emphasis>creation</emphasis> of regular files, directories, pipes, and device nodes, adjustments to
84 their <emphasis>access mode, ownership, attributes, quota assignments, and contents</emphasis>, and
85 finally their time-based <emphasis>removal</emphasis>. It is mostly commonly used for volatile and
86 temporary files and directories (such as those located under <filename>/run/</filename>,
87 <filename>/tmp/</filename>, <filename>/var/tmp/</filename>, the API file systems such as
88 <filename>/sys/</filename> or <filename>/proc/</filename>, as well as some other directories below
89 <filename>/var/</filename>).</para>
90
91 <para><citerefentry><refentrytitle>systemd-tmpfiles</refentrytitle><manvolnum>5</manvolnum></citerefentry>
92 uses this configuration to create volatile files and directories during boot and to do periodic cleanup
93 afterwards. See
94 <citerefentry><refentrytitle>systemd-tmpfiles</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
95 the description of <filename>systemd-tmpfiles-setup.service</filename>,
96 <filename>systemd-tmpfiles-clean.service</filename>, and associated units.</para>
97
98 <para>System daemons frequently require private runtime directories below <filename>/run/</filename> to
99 store communication sockets and similar. For these, it is better to use
100 <varname>RuntimeDirectory=</varname> in their unit files (see
101 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
102 details), if the flexibility provided by <filename>tmpfiles.d</filename> is not required. The advantages
103 are that the configuration required by the unit is centralized in one place, and that the lifetime of the
104 directory is tied to the lifetime of the service itself. Similarly, <varname>StateDirectory=</varname>,
105 <varname>CacheDirectory=</varname>, <varname>LogsDirectory=</varname>, and
106 <varname>ConfigurationDirectory=</varname> should be used to create directories under
107 <filename>/var/lib/</filename>, <filename>/var/cache/</filename>, <filename>/var/log/</filename>, and
108 <filename>/etc/</filename>. <filename>tmpfiles.d</filename> should be used for files whose lifetime is
109 independent of any service or requires more complicated configuration.</para>
110 </refsect1>
111
112 <refsect1>
113 <title>Configuration Directories and Precedence</title>
114
115 <para>Each configuration file shall be named in the style of
116 <filename><replaceable>package</replaceable>.conf</filename> or
117 <filename><replaceable>package</replaceable>-<replaceable>part</replaceable>.conf</filename>.
118 The second variant should be used when it is desirable to make it
119 easy to override just this part of configuration.</para>
120
121 <para>Files in <filename>/etc/tmpfiles.d</filename> override files with the same name in
122 <filename>/usr/lib/tmpfiles.d</filename> and <filename>/run/tmpfiles.d</filename>. Files in
123 <filename>/run/tmpfiles.d</filename> override files with the same name in
124 <filename>/usr/lib/tmpfiles.d</filename>. Packages should install their configuration files in
125 <filename>/usr/lib/tmpfiles.d</filename>. Files in <filename>/etc/tmpfiles.d</filename> are reserved for
126 the local administrator, who may use this logic to override the configuration files installed by vendor
127 packages. All configuration files are sorted by their filename in lexicographic order, regardless of
128 which of the directories they reside in. If multiple files specify the same path, the entry in the file
129 with the lexicographically earliest name will be applied (note that lines suppressed due to the
130 <literal>!</literal> are filtered before application, meaning that if an early line carries the
131 exclamation mark and is suppressed because of that, a later line matching in path will be applied). All
132 other conflicting entries will be logged as errors. When two lines are prefix path and suffix path of
133 each other, then the prefix line is always created first, the suffix later (and if removal applies to the
134 line, the order is reversed: the suffix is removed first, the prefix later). Lines that take globs are
135 applied after those accepting no globs. If multiple operations shall be applied on the same file (such as
136 ACL, xattr, file attribute adjustments), these are always done in the same fixed order. Except for those
137 cases, the files/directories are processed in the order they are listed.</para>
138
139 <para>If the administrator wants to disable a configuration file
140 supplied by the vendor, the recommended way is to place a symlink
141 to <filename>/dev/null</filename> in
142 <filename>/etc/tmpfiles.d/</filename> bearing the same filename.
143 </para>
144 </refsect1>
145
146 <refsect1>
147 <title>Configuration File Format</title>
148
149 <para>The configuration format is one line per path, containing type, path, mode, ownership, age, and
150 argument fields. The lines are separated by newlines, the fields by whitespace:</para>
151
152 <programlisting>#Type Path Mode User Group Age Argument…
153 d /run/user 0755 root root 10d -
154 L /tmp/foobar - - - - /dev/null</programlisting>
155
156 <para>Fields may contain C-style escapes. With the exception of the seventh field (the "argument") all
157 fields may be enclosed in quotes. Note that any whitespace found in the line after the beginning of the
158 argument field will be considered part of the argument field. To begin the argument field with a
159 whitespace character, use C-style escapes (e.g. <literal>\x20</literal>).</para>
160
161 <refsect2>
162 <title>Type</title>
163
164 <para>The type consists of a single letter and optionally one or emore modifier characters: a plus sign
165 (<literal>+</literal>), exclamation mark (<literal>!</literal>), minus sign (<literal>-</literal>),
166 equals sign (<literal>=</literal>), tilde character (<literal>~</literal>) and/or caret
167 (<literal>^</literal>).</para>
168
169 <para>The following line types are understood:</para>
170
171 <variablelist>
172 <varlistentry>
173 <term><varname>f</varname></term>
174 <term><varname>f+</varname></term>
175 <listitem><para><varname>f</varname> will create a file if it does not exist yet. If the argument
176 parameter is given and the file did not exist yet, it will be written to the file.
177 <varname>f+</varname> will create or truncate the file. If the argument parameter is given, it will
178 be written to the file. Does not follow symlinks.</para></listitem>
179 </varlistentry>
180
181 <varlistentry>
182 <term><varname>w</varname></term>
183 <term><varname>w+</varname></term>
184 <listitem><para>Write the argument parameter to a file, if the file exists.
185 If suffixed with <varname>+</varname>, the line will be appended to the file.
186 If your configuration writes multiple lines to the same file, use <varname>w+</varname>.
187 Lines of this type accept shell-style globs in place of normal path names.
188 The argument parameter will be written without a trailing newline.
189 C-style backslash escapes are interpreted. Follows symlinks.</para></listitem>
190 </varlistentry>
191
192 <varlistentry>
193 <term><varname>d</varname></term>
194 <listitem><para>Create a directory. The mode and ownership will be adjusted if specified. Contents
195 of this directory are subject to time based cleanup if the age argument is specified.
196 </para></listitem>
197 </varlistentry>
198
199 <varlistentry>
200 <term><varname>D</varname></term>
201 <listitem><para>Similar to <varname>d</varname>, but in addition the contents of the directory will
202 be removed when <option>--remove</option> is used.</para></listitem>
203 </varlistentry>
204
205 <varlistentry>
206 <term><varname>e</varname></term>
207 <listitem><para>Adjust the mode and ownership of existing directories and remove their contents
208 based on age.
209 Lines of this type accept shell-style globs in place of normal path names. Contents of the
210 directories are subject to time based cleanup if the age argument is specified. If the age argument
211 is <literal>0</literal>, contents will be unconditionally deleted every time
212 <command>systemd-tmpfiles --clean</command> is run.</para>
213
214 <para>For this entry to be useful, at least one of the mode, user, group, or age arguments must be
215 specified, since otherwise this entry has no effect. As an exception, an entry with no effect may
216 be useful when combined with <varname>!</varname>, see the examples.</para></listitem>
217 </varlistentry>
218
219 <varlistentry>
220 <term><varname>v</varname></term>
221 <listitem><para>Create a subvolume if the path does not exist yet, the file system supports
222 subvolumes (btrfs), and the system itself is installed into a subvolume (specifically: the root
223 directory <filename>/</filename> is itself a subvolume). Otherwise, create a normal directory, in
224 the same way as <varname>d</varname>.</para>
225
226 <para>A subvolume created with this line type is not assigned to any higher-level quota group. For
227 that, use <varname>q</varname> or <varname>Q</varname>, which allow creating simple quota group
228 hierarchies, see below.</para></listitem>
229 </varlistentry>
230
231 <varlistentry>
232 <term><varname>q</varname></term>
233 <listitem><para>Create a subvolume or directory the same as <varname>v</varname>, but assign the
234 subvolume to the same higher-level quota groups as the parent. This ensures that higher-level
235 limits and accounting applied to the parent subvolume also include the specified subvolume. On
236 non-btrfs file systems, this line type is identical to <varname>d</varname>.</para>
237
238 <para>If the subvolume already exists, no change to the quota hierarchy is made, regardless of whether the
239 subvolume is already attached to a quota group or not. Also see <varname>Q</varname> below. See <citerefentry
240 project='die-net'><refentrytitle>btrfs-qgroup</refentrytitle><manvolnum>8</manvolnum></citerefentry> for
241 details about the btrfs quota group concept.</para></listitem>
242 </varlistentry>
243
244 <varlistentry>
245 <term><varname>Q</varname></term>
246 <listitem><para>Create the subvolume or directory the same as <varname>v</varname>, but assign the
247 new subvolume to a new leaf quota group. Instead of copying the higher-level quota group
248 assignments from the parent as is done with <varname>q</varname>, the lowest quota group of the
249 parent subvolume is determined that is not the leaf quota group. Then, an "intermediary" quota
250 group is inserted that is one level below this level, and shares the same ID part as the specified
251 subvolume. If no higher-level quota group exists for the parent subvolume, a new quota group at
252 level 255 sharing the same ID as the specified subvolume is inserted instead. This new intermediary
253 quota group is then assigned to the parent subvolume's higher-level quota groups, and the specified
254 subvolume's leaf quota group is assigned to it.</para>
255
256 <para>Effectively, this has a similar effect as <varname>q</varname>, however introduces a new higher-level
257 quota group for the specified subvolume that may be used to enforce limits and accounting to the specified
258 subvolume and children subvolume created within it. Thus, by creating subvolumes only via
259 <varname>q</varname> and <varname>Q</varname>, a concept of "subtree quotas" is implemented. Each subvolume
260 for which <varname>Q</varname> is set will get a "subtree" quota group created, and all child subvolumes
261 created within it will be assigned to it. Each subvolume for which <varname>q</varname> is set will not get
262 such a "subtree" quota group, but it is ensured that they are added to the same "subtree" quota group as
263 their immediate parents.</para>
264
265 <para>It is recommended to use <varname>Q</varname> for subvolumes that typically contain further subvolumes,
266 and where it is desirable to have accounting and quota limits on all child subvolumes together. Examples for
267 <varname>Q</varname> are typically <filename>/home/</filename> or <filename>/var/lib/machines/</filename>. In
268 contrast, <varname>q</varname> should be used for subvolumes that either usually do not include further
269 subvolumes or where no accounting and quota limits are needed that apply to all child subvolumes
270 together. Examples for <varname>q</varname> are typically <filename>/var/</filename> or
271 <filename>/var/tmp/</filename>. </para>
272
273 <para>As with <varname>q</varname>, <varname>Q</varname> has no effect on the quota group hierarchy if the
274 subvolume already exists, regardless of whether the subvolume already belong to a quota group or not.
275 </para></listitem>
276 </varlistentry>
277
278 <varlistentry>
279 <term><varname>p</varname></term>
280 <term><varname>p+</varname></term>
281 <listitem><para>Create a named pipe (FIFO) if it does not
282 exist yet. If suffixed with <varname>+</varname> and a file
283 already exists where the pipe is to be created, it will be
284 removed and be replaced by the pipe.</para></listitem>
285 </varlistentry>
286
287 <varlistentry>
288 <term><varname>L</varname></term>
289 <term><varname>L+</varname></term>
290 <listitem><para>Create a symlink if it does not exist
291 yet. If suffixed with <varname>+</varname> and a file or
292 directory already exists where the symlink is to be created,
293 it will be removed and be replaced by the symlink. If the
294 argument is omitted, symlinks to files with the same name
295 residing in the directory
296 <filename>/usr/share/factory/</filename> are created. Note
297 that permissions and ownership on symlinks are ignored.
298 </para></listitem>
299 </varlistentry>
300
301 <varlistentry>
302 <term><varname>c</varname></term>
303 <term><varname>c+</varname></term>
304 <listitem><para>Create a character device node if it does
305 not exist yet. If suffixed with <varname>+</varname> and a
306 file already exists where the device node is to be created,
307 it will be removed and be replaced by the device node. It is
308 recommended to suffix this entry with an exclamation mark to
309 only create static device nodes at boot, as udev will not
310 manage static device nodes that are created at runtime.
311 </para></listitem>
312 </varlistentry>
313
314 <varlistentry>
315 <term><varname>b</varname></term>
316 <term><varname>b+</varname></term>
317 <listitem><para>Create a block device node if it does not
318 exist yet. If suffixed with <varname>+</varname> and a file
319 already exists where the device node is to be created, it
320 will be removed and be replaced by the device node. It is
321 recommended to suffix this entry with an exclamation mark to
322 only create static device nodes at boot, as udev will not
323 manage static device nodes that are created at runtime.
324 </para></listitem>
325 </varlistentry>
326
327 <varlistentry>
328 <term><varname>C</varname></term>
329 <listitem><para>Recursively copy a file or directory, if the
330 destination files or directories do not exist yet or the
331 destination directory is empty. Note that this command will not
332 descend into subdirectories if the destination directory already
333 exists and is not empty. Instead, the entire copy operation is
334 skipped. If the argument is omitted, files from the source directory
335 <filename>/usr/share/factory/</filename> with the same name
336 are copied. Does not follow symlinks. Contents of the directories
337 are subject to time based cleanup if the age argument is specified.
338 </para></listitem>
339 </varlistentry>
340
341 <varlistentry>
342 <term><varname>x</varname></term>
343 <listitem><para>Ignore a path during cleaning. Use this type
344 to exclude paths from clean-up as controlled with the Age
345 parameter. Note that lines of this type do not influence the
346 effect of <varname>r</varname> or <varname>R</varname>
347 lines. Lines of this type accept shell-style globs in place
348 of normal path names. </para></listitem>
349 </varlistentry>
350
351 <varlistentry>
352 <term><varname>X</varname></term>
353 <listitem><para>Ignore a path during cleaning. Use this type
354 to exclude paths from clean-up as controlled with the Age
355 parameter. Unlike <varname>x</varname>, this parameter will
356 not exclude the content if path is a directory, but only
357 directory itself. Note that lines of this type do not
358 influence the effect of <varname>r</varname> or
359 <varname>R</varname> lines. Lines of this type accept
360 shell-style globs in place of normal path names.
361 </para></listitem>
362 </varlistentry>
363
364 <varlistentry>
365 <term><varname>r</varname></term>
366 <listitem><para>Remove a file or directory if it exists.
367 This may not be used to remove non-empty directories, use
368 <varname>R</varname> for that. Lines of this type accept
369 shell-style globs in place of normal path
370 names. Does not follow symlinks.</para></listitem>
371 </varlistentry>
372
373 <varlistentry>
374 <term><varname>R</varname></term>
375 <listitem><para>Recursively remove a path and all its
376 subdirectories (if it is a directory). Lines of this type
377 accept shell-style globs in place of normal path
378 names. Does not follow symlinks.</para></listitem>
379 </varlistentry>
380
381 <varlistentry>
382 <term><varname>z</varname></term>
383 <listitem><para>Adjust the access mode, user and group ownership, and restore the SELinux security
384 context of a file or directory, if it exists. Lines of this type accept shell-style globs in place
385 of normal path names. Does not follow symlinks.</para></listitem>
386 </varlistentry>
387
388 <varlistentry>
389 <term><varname>Z</varname></term>
390 <listitem><para>Recursively set the access mode, user and group ownership, and restore the SELinux
391 security context of a file or directory if it exists, as well as of its subdirectories and the
392 files contained therein (if applicable). Lines of this type accept shell-style globs in place of
393 normal path names. Does not follow symlinks.</para></listitem>
394 </varlistentry>
395
396 <varlistentry>
397 <term><varname>t</varname></term>
398 <listitem><para>Set extended attributes, see <citerefentry
399 project='man-pages'><refentrytitle>attr</refentrytitle>
400 <manvolnum>5</manvolnum></citerefentry> for details. The argument field should take one or more
401 assignment expressions in the form
402 <replaceable>namespace</replaceable>.<replaceable>attribute</replaceable>=<replaceable>value</replaceable>,
403 for examples see below. Lines of this type accept shell-style globs in place of normal path
404 names. This can be useful for setting SMACK labels. Does not follow symlinks.</para>
405
406 <para>Please note that extended attributes settable with this line type are a different concept
407 from the Linux file attributes settable with <varname>h</varname>/<varname>H</varname>, see
408 below.</para></listitem>
409 </varlistentry>
410
411 <varlistentry>
412 <term><varname>T</varname></term>
413 <listitem><para>Same as <varname>t</varname>, but operates recursively.</para></listitem>
414 </varlistentry>
415
416 <varlistentry>
417 <term><varname>h</varname></term>
418 <listitem><para>Set Linux file/directory attributes. Lines of this type accept shell-style globs in
419 place of normal path names.</para>
420
421 <para>The format of the argument field is <varname>[+-=][aAcCdDeijPsStTu]</varname>. The prefix
422 <varname>+</varname> (the default one) causes the attributes to be added; <varname>-</varname>
423 causes the attributes to be removed; <varname>=</varname> causes the attributes to be set exactly
424 as the following letters. The letters <literal>aAcCdDeijPsStTu</literal> select the new attributes
425 for the files, see <citerefentry project='man-pages'><refentrytitle>chattr</refentrytitle>
426 <manvolnum>1</manvolnum></citerefentry> for further information.
427 </para>
428
429 <para>Passing only <varname>=</varname> as argument resets all the file attributes listed above. It
430 has to be pointed out that the <varname>=</varname> prefix limits itself to the attributes
431 corresponding to the letters listed here. All other attributes will be left untouched. Does not
432 follow symlinks.</para>
433
434 <para>Please note that the Linux file attributes settable with this line type are a different
435 concept from the extended attributes settable with <varname>t</varname>/<varname>T</varname>,
436 see above.</para></listitem>
437 </varlistentry>
438
439 <varlistentry>
440 <term><varname>H</varname></term>
441 <listitem><para>Sames as <varname>h</varname>, but operates recursively.</para></listitem>
442 </varlistentry>
443
444 <varlistentry>
445 <term><varname>a</varname></term>
446 <term><varname>a+</varname></term>
447 <listitem><para>Set POSIX ACLs (access control lists), see <citerefentry
448 project='man-pages'><refentrytitle>acl</refentrytitle>
449 <manvolnum>5</manvolnum></citerefentry>. If suffixed with <varname>+</varname>, the specified
450 entries will be added to the existing set. <command>systemd-tmpfiles</command> will automatically
451 add the required base entries for user and group based on the access mode of the file, unless base
452 entries already exist or are explicitly specified. The mask will be added if not specified
453 explicitly or already present. Lines of this type accept shell-style globs in place of normal path
454 names. This can be useful for allowing additional access to certain files. Does not follow
455 symlinks.</para></listitem>
456 </varlistentry>
457
458 <varlistentry>
459 <term><varname>A</varname></term>
460 <term><varname>A+</varname></term>
461 <listitem><para>Same as <varname>a</varname> and
462 <varname>a+</varname>, but recursive. Does not follow
463 symlinks.</para></listitem>
464 </varlistentry>
465 </variablelist>
466 </refsect2>
467
468 <refsect2>
469 <title>Type Modifiers</title>
470
471 <para>If the exclamation mark (<literal>!</literal>) is used, this line is only safe to execute during
472 boot, and can break a running system. Lines without the exclamation mark are presumed to be safe to
473 execute at any time, e.g. on package upgrades. <command>systemd-tmpfiles</command> will take lines with
474 an exclamation mark only into consideration, if the <option>--boot</option> option is given.</para>
475
476 <para>For example:
477 <programlisting># Make sure these are created by default so that nobody else can
478 d /tmp/.X11-unix 1777 root root 10d
479
480 # Unlink the X11 lock files
481 r! /tmp/.X[0-9]*-lock</programlisting>
482 The second line in contrast to the first one would break a
483 running system, and will only be executed with
484 <option>--boot</option>.</para>
485
486 <para>If the minus sign (<literal>-</literal>) is used, this line failing to run successfully during
487 create (and only create) will not cause the execution of <command>systemd-tmpfiles</command> to return
488 an error.</para>
489
490 <para>For example:
491 <programlisting># Modify sysfs but don't fail if we are in a container with a read-only /proc
492 w- /proc/sys/vm/swappiness - - - - 10</programlisting></para>
493
494 <para>If the equals sign (<literal>=</literal>) is used, the file types of existing objects in the specified path
495 are checked, and removed if they do not match. This includes any implicitly created parent directories (which can
496 be either directories or directory symlinks). For example, if there is a FIFO in place of one of the parent path
497 components it will be replaced with a directory.</para>
498
499 <para>If the tilde character (<literal>~</literal>) is used, the argument (i.e. 6th) column is <ulink
500 url="https://www.rfc-editor.org/rfc/rfc4648.html">Base64 decoded</ulink> before use. This modifier is
501 only supported on line types that can write file contents, i.e. <varname>f</varname>,
502 <varname>f+</varname>, <varname>w</varname>, <varname>+</varname>. This is useful for writing arbitrary
503 binary data (including newlines and NUL bytes) to files. Note that if this switch is used, the argument
504 is not subject to specifier expansion, neither before nor after Base64 decoding.</para>
505
506 <para>If the caret character (<literal>^</literal>) is used, the argument (i.e. 6th) column takes a
507 service credential name to read the argument data from. See <ulink
508 url="https://systemd.io/CREDENTIALS">System and Service Credentials</ulink> for details about the
509 credentials concept. This modifier is only supported on line types that can write file contents,
510 i.e. <varname>f</varname>, <varname>f+</varname>, <varname>w</varname>, <varname>w+</varname>. This is
511 useful for writing arbitrary files with contents sourced from elsewhere, including from VM or container
512 managers further up. If the specified credential is not set for the <command>systemd-tmpfiles</command>
513 service, the line is silently skipped. If <literal>^</literal> and <literal>~</literal> are combined
514 Base64 decoding is applied to the credential contents.</para>
515
516 <para>Note that for all line types that result in creation of any kind of file node
517 (i.e. <varname>f</varname>/<varname>F</varname>,
518 <varname>d</varname>/<varname>D</varname>/<varname>v</varname>/<varname>q</varname>/<varname>Q</varname>,
519 <varname>p</varname>, <varname>L</varname>, <varname>c</varname>/<varname>b</varname> and <varname>C</varname>)
520 leading directories are implicitly created if needed, owned by root with an access mode of 0755. In order to
521 create them with different modes or ownership make sure to add appropriate <varname>d</varname> lines.</para>
522 </refsect2>
523
524 <refsect2>
525 <title>Path</title>
526
527 <para>The file system path specification supports simple
528 specifier expansion, see below. The path (after expansion) must be
529 absolute.</para>
530 </refsect2>
531
532 <refsect2>
533 <title>Mode</title>
534
535 <para>The file access mode to use when creating this file or directory. If omitted or when set to
536 <literal>-</literal>, the default is used: 0755 for directories, 0644 for all other file objects. For
537 <varname>z</varname>, <varname>Z</varname> lines, if omitted or when set to <literal>-</literal>, the
538 file access mode will not be modified. This parameter is ignored for <varname>x</varname>,
539 <varname>r</varname>, <varname>R</varname>, <varname>L</varname>, <varname>t</varname>, and
540 <varname>a</varname> lines.</para>
541
542 <para>Optionally, if prefixed with <literal>~</literal>, the access mode is masked based on the already
543 set access bits for existing file or directories: if the existing file has all executable bits unset,
544 all executable bits are removed from the new access mode, too. Similarly, if all read bits are removed
545 from the old access mode, they will be removed from the new access mode too, and if all write bits are
546 removed, they will be removed from the new access mode too. In addition, the sticky/SUID/SGID bit is
547 removed unless applied to a directory. This functionality is particularly useful in conjunction with
548 <varname>Z</varname>.</para>
549
550 <para>Optionally, if prefixed with <literal>:</literal>, the configured access mode is only used when
551 creating new inodes. If the inode the line refers to already exists, its access mode is left in place
552 unmodified.</para>
553 </refsect2>
554
555 <refsect2>
556 <title>User, Group</title>
557
558 <para>The user and group to use for this file or directory. This may either be a numeric ID or a
559 user/group name. If omitted or when set to <literal>-</literal>, the user and group of the user who
560 invokes <command>systemd-tmpfiles</command> is used. For <varname>z</varname> and <varname>Z</varname>
561 lines, when omitted or when set to <literal>-</literal>, the file ownership will not be modified. These
562 parameters are ignored for <varname>x</varname>, <varname>r</varname>, <varname>R</varname>,
563 <varname>L</varname>, <varname>t</varname>, and <varname>a</varname> lines.</para>
564
565 <para>This field should generally only reference system users/groups, i.e. users/groups that are
566 guaranteed to be resolvable during early boot. If this field references users/groups that only become
567 resolveable during later boot (i.e. after NIS, LDAP or a similar networked directory service become
568 available), execution of the operations declared by the line will likely fail. Also see <ulink
569 url="https://systemd.io/UIDS-GIDS/#notes-on-resolvability-of-user-and-group-names">Notes on
570 Resolvability of User and Group Names</ulink> for more information on requirements on system user/group
571 definitions.</para>
572
573 <para>Optionally, if prefixed with <literal>:</literal>, the configured user/group information is only
574 used when creating new inodes. If the inode the line refers to already exists, its user/group is left
575 in place unmodified.</para>
576 </refsect2>
577
578 <refsect2>
579 <title>Age</title>
580
581 <para>The date field, when set, is used to decide what files to
582 delete when cleaning. If a file or directory is older than the
583 current time minus the age field, it is deleted. The field
584 format is a series of integers each followed by one of the
585 following suffixes for the respective time units:
586 <constant>s</constant>,
587 <constant>m</constant> or <constant>min</constant>,
588 <constant>h</constant>,
589 <constant>d</constant>,
590 <constant>w</constant>,
591 <constant>ms</constant>, and
592 <constant>us</constant>,
593 meaning seconds, minutes, hours, days, weeks,
594 milliseconds, and microseconds, respectively. Full names of the time units can
595 be used too.
596 </para>
597
598 <para>If multiple integers and units are specified, the time
599 values are summed. If an integer is given without a unit,
600 <constant>s</constant> is assumed.
601 </para>
602
603 <para>When the age is set to zero, the files are cleaned
604 unconditionally.</para>
605
606 <para>The age field only applies to lines starting with
607 <varname>d</varname>, <varname>D</varname>, <varname>e</varname>,
608 <varname>v</varname>, <varname>q</varname>,
609 <varname>Q</varname>, <varname>C</varname>, <varname>x</varname>
610 and <varname>X</varname>. If omitted or set to
611 <literal>-</literal>, no automatic clean-up is done.</para>
612
613 <para>If the age field starts with a tilde character <literal>~</literal>, clean-up is only applied to
614 files and directories one level inside the directory specified, but not the files and directories
615 immediately inside it.</para>
616
617 <para>The age of a file system entry is determined from its last
618 modification timestamp (mtime), its last access timestamp (atime),
619 and (except for directories) its last status change timestamp
620 (ctime). By default, any of these three (or two) values will
621 prevent cleanup if it is more recent than the current time minus
622 the age field. To restrict the deletion based on particular type
623 of file timestamps, the age-by argument can be used.</para>
624
625 <para>The age-by argument overrides the timestamp types to be used for the age check. It can be
626 specified by prefixing the age argument with a sequence of characters to specify the timestamp types
627 and a colon (<literal>:</literal>):
628 <literal><replaceable>age-by</replaceable>...:<replaceable>cleanup-age</replaceable></literal>. The
629 argument can consist of <constant>a</constant> (<constant>A</constant> for directories),
630 <constant>b</constant> (<constant>B</constant> for directories), <constant>c</constant>
631 (<constant>C</constant> for directories), or <constant>m</constant> (<constant>M</constant> for
632 directories). Those respectively indicate access, creation, last status change, and last modification
633 time of a file system entry. The lower-case letter signifies that the given timestamp type should be
634 considered for files, while the upper-case letter signifies that the given timestamp type should be
635 considered for directories. See <citerefentry
636 project='man-pages'><refentrytitle>statx</refentrytitle><manvolnum>2</manvolnum></citerefentry> file
637 timestamp fields for more details about timestamp types.</para>
638
639 <para>If not specified, the age-by field defaults to <constant>abcmABM</constant>, i.e. by default all
640 file timestamps are taken into consideration, with the exception of the last status change timestamp
641 (ctime) for directories. This is because the aging logic itself will alter the ctime whenever it
642 deletes a file inside it. To ensure that running the aging logic does not feed back into the next
643 iteration of itself, ctime for directories is ignored by default.</para>
644
645 <para>For example:<programlisting>
646 # Files created and modified, and directories accessed more than
647 # an hour ago in "/tmp/foo/bar", are subject to time-based cleanup.
648 d /tmp/foo/bar - - - - bmA:1h -</programlisting></para>
649
650 <para>Note that while the aging algorithm is run a 'shared' BSD file lock (see <citerefentry
651 project='man-pages'><refentrytitle>flock</refentrytitle><manvolnum>2</manvolnum></citerefentry>) is
652 taken on each directory the algorithm descends into (and each directory below that, and so on). If the
653 aging algorithm finds a lock is already taken on some directory, it (and everything below it) is
654 skipped. Applications may use this to temporarily exclude certain directory subtrees from the aging
655 algorithm: the applications can take a BSD file lock themselves, and as long as they keep it aging of
656 the directory and everything below it is disabled.</para>
657 </refsect2>
658
659 <refsect2>
660 <title>Argument</title>
661
662 <para>For <varname>L</varname> lines determines the destination path of the symlink. For <varname>c</varname> and
663 <varname>b</varname>, determines the major/minor of the device node, with major and minor formatted as integers,
664 separated by <literal>:</literal>, e.g. <literal>1:3</literal>. For <varname>f</varname>, <varname>F</varname>,
665 and <varname>w</varname>, the argument may be used to specify a short string that is written to the file,
666 suffixed by a newline. For <varname>C</varname>, specifies the source file or directory. For <varname>t</varname>
667 and <varname>T</varname>, determines extended attributes to be set. For <varname>a</varname> and
668 <varname>A</varname>, determines ACL attributes to be set. For <varname>h</varname> and <varname>H</varname>,
669 determines the file attributes to set. Ignored for all other lines.</para>
670
671 <para>This field can contain specifiers, see below.</para>
672 </refsect2>
673 </refsect1>
674
675 <refsect1>
676 <title>Specifiers</title>
677
678 <para>Specifiers can be used in the "path" and "argument" fields.
679 An unknown or unresolvable specifier is treated as invalid configuration.
680 The following expansions are understood:</para>
681 <table class='specifiers'>
682 <title>Specifiers available</title>
683 <tgroup cols='3' align='left' colsep='1' rowsep='1'>
684 <colspec colname="spec" />
685 <colspec colname="mean" />
686 <colspec colname="detail" />
687 <thead>
688 <row>
689 <entry>Specifier</entry>
690 <entry>Meaning</entry>
691 <entry>Details</entry>
692 </row>
693 </thead>
694 <tbody>
695 <xi:include href="standard-specifiers.xml" xpointer="a"/>
696 <xi:include href="standard-specifiers.xml" xpointer="A"/>
697 <xi:include href="standard-specifiers.xml" xpointer="b"/>
698 <xi:include href="standard-specifiers.xml" xpointer="B"/>
699 <row>
700 <entry><literal>%C</literal></entry>
701 <entry>System or user cache directory</entry>
702 <entry>In <option>--user</option> mode, this is the same as <varname>$XDG_CACHE_HOME</varname>, and <filename>/var/cache</filename> otherwise.</entry>
703 </row>
704 <row>
705 <entry><literal>%g</literal></entry>
706 <entry>User group</entry>
707 <entry>This is the name of the group running the command. In case of the system instance this resolves to <literal>root</literal>.</entry>
708 </row>
709 <row>
710 <entry><literal>%G</literal></entry>
711 <entry>User GID</entry>
712 <entry>This is the numeric GID of the group running the command. In case of the system instance this resolves to <constant>0</constant>.</entry>
713 </row>
714 <row>
715 <entry><literal>%h</literal></entry>
716 <entry>User home directory</entry>
717 <entry>This is the home directory of the user running the command. In case of the system instance this resolves to <literal>/root</literal>.</entry>
718 </row>
719 <xi:include href="standard-specifiers.xml" xpointer="H"/>
720 <xi:include href="standard-specifiers.xml" xpointer="l"/>
721 <row>
722 <entry><literal>%L</literal></entry>
723 <entry>System or user log directory</entry>
724 <entry>In <option>--user</option> mode, this is the same as <varname>$XDG_CONFIG_HOME</varname> with <filename index="false">/log</filename> appended, and <filename>/var/log</filename> otherwise.</entry>
725 </row>
726 <xi:include href="standard-specifiers.xml" xpointer="m"/>
727 <xi:include href="standard-specifiers.xml" xpointer="M"/>
728 <xi:include href="standard-specifiers.xml" xpointer="o"/>
729 <row>
730 <entry><literal>%S</literal></entry>
731 <entry>System or user state directory</entry>
732 <entry>In <option>--user</option> mode, this is the same as <varname>$XDG_CONFIG_HOME</varname>, and <filename>/var/lib</filename> otherwise.</entry>
733 </row>
734 <row>
735 <entry><literal>%t</literal></entry>
736 <entry>System or user runtime directory</entry>
737 <entry>In <option>--user</option> mode, this is the same <varname>$XDG_RUNTIME_DIR</varname>, and <filename>/run/</filename> otherwise.</entry>
738 </row>
739 <xi:include href="standard-specifiers.xml" xpointer="T"/>
740 <row>
741 <entry><literal>%u</literal></entry>
742 <entry>User name</entry>
743 <entry>This is the name of the user running the command. In case of the system instance this resolves to <literal>root</literal>.</entry>
744 </row>
745 <row>
746 <entry><literal>%U</literal></entry>
747 <entry>User UID</entry>
748 <entry>This is the numeric UID of the user running the command. In case of the system instance this resolves to <constant>0</constant>.</entry>
749 </row>
750 <xi:include href="standard-specifiers.xml" xpointer="v"/>
751 <xi:include href="standard-specifiers.xml" xpointer="V"/>
752 <xi:include href="standard-specifiers.xml" xpointer="w"/>
753 <xi:include href="standard-specifiers.xml" xpointer="W"/>
754 <xi:include href="standard-specifiers.xml" xpointer="percent"/>
755 </tbody>
756 </tgroup>
757 </table>
758 </refsect1>
759
760 <refsect1>
761 <title>Examples</title>
762 <example>
763 <title>Create directories with specific mode and ownership</title>
764 <para>
765 <citerefentry project='die-net'><refentrytitle>screen</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
766 needs two directories created at boot with specific modes and ownership:</para>
767
768 <programlisting># /usr/lib/tmpfiles.d/screen.conf
769 d /run/screens 1777 root screen 10d
770 d /run/uscreens 0755 root screen 10d12h
771 </programlisting>
772
773 <para>Contents of <filename>/run/screens</filename> and /run/uscreens will
774 be cleaned up after 10 and 10½ days, respectively.</para>
775 </example>
776
777 <example>
778 <title>Create a directory with a SMACK attribute</title>
779 <programlisting>D /run/cups - - - -
780 t /run/cups - - - - security.SMACK64=printing user.attr-with-spaces="foo bar"
781 </programlisting>
782
783 <para>The directory will be owned by root and have default mode. Its contents are
784 not subject to time based cleanup, but will be obliterated when
785 <command>systemd-tmpfiles --remove</command> runs.</para>
786 </example>
787
788 <example>
789 <title>Create a directory and prevent its contents from cleanup</title>
790 <para>
791 <citerefentry project='die-net'><refentrytitle>abrt</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
792 needs a directory created at boot with specific mode and ownership and its content
793 should be preserved from the automatic cleanup applied to the contents of
794 <filename>/var/tmp</filename>:</para>
795
796 <programlisting># /usr/lib/tmpfiles.d/tmp.conf
797 d /var/tmp 1777 root root 30d
798 </programlisting>
799
800 <programlisting># /usr/lib/tmpfiles.d/abrt.conf
801 d /var/tmp/abrt 0755 abrt abrt -
802 </programlisting>
803 </example>
804
805 <example>
806 <title>Apply clean up during boot and based on time</title>
807
808 <programlisting># /usr/lib/tmpfiles.d/dnf.conf
809 r! /var/cache/dnf/*/*/download_lock.pid
810 r! /var/cache/dnf/*/*/metadata_lock.pid
811 r! /var/lib/dnf/rpmdb_lock.pid
812 e /var/cache/dnf/ - - - 30d
813 </programlisting>
814
815 <para>The lock files will be removed during boot. Any files and directories in
816 <filename>/var/cache/dnf/</filename> will be removed after they have not been
817 accessed in 30 days.</para>
818 </example>
819
820 <example>
821 <title>Empty the contents of a cache directory on boot</title>
822
823 <programlisting># /usr/lib/tmpfiles.d/krb5rcache.conf
824 e! /var/cache/krb5rcache - - - 0
825 </programlisting>
826
827 <para>Any files and subdirectories in <filename>/var/cache/krb5rcache/</filename>
828 will be removed on boot. The directory will not be created.
829 </para>
830 </example>
831
832 <example>
833 <title>Provision SSH public key access for root user via Credentials in QEMU</title>
834
835 <programlisting>-smbios type=11,value=io.systemd.credential.binary:tmpfiles.extra=$(echo "f~ /root/.ssh/authorized_keys 700 root root - $(ssh-add -L | base64 -w 0)" | base64 -w 0)
836 </programlisting>
837
838 <para>By passing this line to QEMU, the public key of the current user will be encoded in
839 base64, added to a tmpfiles.d line that tells systemd-tmpfiles to decode it into
840 <filename>/root/.ssh/authorized_keys</filename>, encode that line itself in base64 and
841 pass it as a Credential that will be picked up by systemd from SMBIOS on boot.
842 </para>
843 </example>
844 </refsect1>
845
846 <refsect1>
847 <title><filename>/run/</filename> and <filename>/var/run/</filename></title>
848 <para><filename>/var/run/</filename> is a deprecated symlink to <filename>/run/</filename>, and
849 applications should use the latter. <command>systemd-tmpfiles</command> will warn if
850 <filename>/var/run/</filename> is used.</para>
851 </refsect1>
852
853 <refsect1>
854 <title>See Also</title>
855 <para>
856 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
857 <citerefentry><refentrytitle>systemd-tmpfiles</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
858 <citerefentry><refentrytitle>systemd-delta</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
859 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
860 <citerefentry project='man-pages'><refentrytitle>attr</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
861 <citerefentry project='man-pages'><refentrytitle>getfattr</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
862 <citerefentry project='man-pages'><refentrytitle>setfattr</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
863 <citerefentry project='man-pages'><refentrytitle>setfacl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
864 <citerefentry project='man-pages'><refentrytitle>getfacl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
865 <citerefentry project='man-pages'><refentrytitle>chattr</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
866 <citerefentry project='die-net'><refentrytitle>btrfs-subvolume</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
867 <citerefentry project='die-net'><refentrytitle>btrfs-qgroup</refentrytitle><manvolnum>8</manvolnum></citerefentry>
868 </para>
869 </refsect1>
870
871 </refentry>