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