| 1 |
<?xml version='1.0'?> <!--*-nxml-*--> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="systemd-tmpfiles" |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>systemd-tmpfiles</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
|
| 14 |
<refmeta> |
| 15 |
<refentrytitle>systemd-tmpfiles</refentrytitle> |
| 16 |
<manvolnum>8</manvolnum> |
| 17 |
</refmeta> |
| 18 |
|
| 19 |
<refnamediv> |
| 20 |
<refname>systemd-tmpfiles</refname> |
| 21 |
<refname>systemd-tmpfiles-setup.service</refname> |
| 22 |
<refname>systemd-tmpfiles-setup-dev-early.service</refname> |
| 23 |
<refname>systemd-tmpfiles-setup-dev.service</refname> |
| 24 |
<refname>systemd-tmpfiles-clean.service</refname> |
| 25 |
<refname>systemd-tmpfiles-clean.timer</refname> |
| 26 |
<refpurpose>Create, delete, and clean up files and directories</refpurpose> |
| 27 |
</refnamediv> |
| 28 |
|
| 29 |
<refsynopsisdiv> |
| 30 |
<cmdsynopsis> |
| 31 |
<command>systemd-tmpfiles</command> |
| 32 |
<arg choice="opt" rep="repeat">OPTIONS</arg> |
| 33 |
<arg choice="opt" rep="repeat"><replaceable>CONFIGFILE</replaceable></arg> |
| 34 |
</cmdsynopsis> |
| 35 |
|
| 36 |
<para>System units: |
| 37 |
<simplelist> |
| 38 |
<member><filename>systemd-tmpfiles-setup.service</filename></member> |
| 39 |
<member><filename>systemd-tmpfiles-setup-dev-early.service</filename></member> |
| 40 |
<member><filename>systemd-tmpfiles-setup-dev.service</filename></member> |
| 41 |
<member><filename>systemd-tmpfiles-clean.service</filename></member> |
| 42 |
<member><filename>systemd-tmpfiles-clean.timer</filename></member> |
| 43 |
</simplelist> |
| 44 |
</para> |
| 45 |
|
| 46 |
<para>User units: |
| 47 |
<simplelist> |
| 48 |
<member><filename>systemd-tmpfiles-setup.service</filename></member> |
| 49 |
<member><filename>systemd-tmpfiles-clean.service</filename></member> |
| 50 |
<member><filename>systemd-tmpfiles-clean.timer</filename></member> |
| 51 |
</simplelist> |
| 52 |
</para> |
| 53 |
</refsynopsisdiv> |
| 54 |
|
| 55 |
<refsect1> |
| 56 |
<title>Description</title> |
| 57 |
|
| 58 |
<para><command>systemd-tmpfiles</command> creates, deletes, and cleans up files and directories, using |
| 59 |
the configuration file format and location specified in |
| 60 |
<citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 61 |
Historically, it was designed to manage volatile and temporary files, as the name suggests, but it provides |
| 62 |
generic file management functionality and can be used to manage any kind of files. It must |
| 63 |
be invoked with one or more commands <option>--create</option>, <option>--remove</option>, and |
| 64 |
<option>--clean</option>, to select the respective subset of operations.</para> |
| 65 |
|
| 66 |
<para>If invoked with no arguments, directives from the configuration files found in the directories |
| 67 |
specified by |
| 68 |
<citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> are |
| 69 |
executed. When invoked with positional arguments, if option |
| 70 |
<option>--replace=<replaceable>PATH</replaceable></option> is specified, arguments specified on the |
| 71 |
command line are used instead of the configuration file <replaceable>PATH</replaceable>. Otherwise, just |
| 72 |
the configuration specified by the command line arguments is executed. If the string <literal>-</literal> |
| 73 |
is specified instead of a filename, the configuration is read from standard input. If the argument is a |
| 74 |
file name (without any slashes), all configuration directories are searched for a matching file and the |
| 75 |
file found that has the highest priority is executed. If the argument is a path, that file is used |
| 76 |
directly without searching the configuration directories for any other matching file.</para> |
| 77 |
|
| 78 |
<para>System services (<filename>systemd-tmpfiles-setup.service</filename>, |
| 79 |
<filename>systemd-tmpfiles-setup-dev-early.service</filename>, |
| 80 |
<filename>systemd-tmpfiles-setup-dev.service</filename>, |
| 81 |
<filename>systemd-tmpfiles-clean.service</filename>) invoke <command>systemd-tmpfiles</command> to create |
| 82 |
system files and to perform system wide cleanup. Those services read administrator-controlled |
| 83 |
configuration files in <filename>tmpfiles.d/</filename> directories. User services |
| 84 |
(<filename>systemd-tmpfiles-setup.service</filename>, |
| 85 |
<filename>systemd-tmpfiles-clean.service</filename>) also invoke <command>systemd-tmpfiles</command>, but |
| 86 |
it reads a separate set of files, which includes user-controlled files under |
| 87 |
<filename>~/.config/user-tmpfiles.d/</filename> and <filename>~/.local/share/user-tmpfiles.d/</filename>, |
| 88 |
and administrator-controlled files under <filename>/usr/share/user-tmpfiles.d/</filename>. Users may use |
| 89 |
this to create and clean up files under their control, but the system instance performs global cleanup |
| 90 |
and is not influenced by user configuration. Note that this means a time-based cleanup configured in the |
| 91 |
system instance, such as the one typically configured for <filename>/tmp/</filename>, will thus also |
| 92 |
affect files created by the user instance if they are placed in <filename>/tmp/</filename>, even if the |
| 93 |
user instance's time-based cleanup is turned off.</para> |
| 94 |
|
| 95 |
<para>To re-apply settings after configuration has been modified, simply restart |
| 96 |
<filename>systemd-tmpfiles-clean.service</filename>, which will apply any settings which can be safely |
| 97 |
executed at runtime. To debug <command>systemd-tmpfiles</command>, it may be useful to invoke it |
| 98 |
directly from the command line with increased log level (see <varname>$SYSTEMD_LOG_LEVEL</varname> |
| 99 |
below).</para> |
| 100 |
</refsect1> |
| 101 |
|
| 102 |
<refsect1> |
| 103 |
<title>Commands and options</title> |
| 104 |
|
| 105 |
<para>The following commands are understood:</para> |
| 106 |
|
| 107 |
<variablelist> |
| 108 |
<varlistentry> |
| 109 |
<term><option>--create</option></term> |
| 110 |
<listitem><para>If this command is passed, all files and |
| 111 |
directories marked with |
| 112 |
<varname>f</varname>, |
| 113 |
<varname>F</varname>, |
| 114 |
<varname>w</varname>, |
| 115 |
<varname>d</varname>, |
| 116 |
<varname>D</varname>, |
| 117 |
<varname>v</varname>, |
| 118 |
<varname>p</varname>, |
| 119 |
<varname>L</varname>, |
| 120 |
<varname>c</varname>, |
| 121 |
<varname>b</varname>, |
| 122 |
<varname>m</varname> |
| 123 |
in the configuration files are created or written to. Files |
| 124 |
and directories marked with |
| 125 |
<varname>z</varname>, |
| 126 |
<varname>Z</varname>, |
| 127 |
<varname>t</varname>, |
| 128 |
<varname>T</varname>, |
| 129 |
<varname>a</varname>, and |
| 130 |
<varname>A</varname> have their ownership, access mode and |
| 131 |
security labels set.</para></listitem> |
| 132 |
</varlistentry> |
| 133 |
|
| 134 |
<varlistentry> |
| 135 |
<term><option>--clean</option></term> |
| 136 |
<listitem><para>If this command is passed, all files and |
| 137 |
directories with an age parameter configured will be cleaned |
| 138 |
up.</para></listitem> |
| 139 |
</varlistentry> |
| 140 |
|
| 141 |
<varlistentry> |
| 142 |
<term><option>--remove</option></term> |
| 143 |
<listitem><para>If this command is passed, the contents of |
| 144 |
directories marked with <varname>D</varname> or |
| 145 |
<varname>R</varname>, and files or directories themselves |
| 146 |
marked with <varname>r</varname> or <varname>R</varname> are |
| 147 |
removed unless an exclusive or shared BSD lock is taken on them (see <citerefentry |
| 148 |
project='man-pages'><refentrytitle>flock</refentrytitle><manvolnum>2</manvolnum></citerefentry>). |
| 149 |
</para></listitem> |
| 150 |
</varlistentry> |
| 151 |
|
| 152 |
<varlistentry> |
| 153 |
<term><option>--purge</option></term> |
| 154 |
|
| 155 |
<listitem><para>If this option is passed, all files and directories declared for |
| 156 |
<emphasis>creation</emphasis> and marked with the <literal>$</literal> character by the |
| 157 |
<filename>tmpfiles.d/</filename> files specified on the command line will be |
| 158 |
<emphasis>deleted</emphasis>. Specifically, this acts on all files and directories marked with |
| 159 |
<varname>f</varname>, <varname>F</varname>, <varname>d</varname>, <varname>D</varname>, |
| 160 |
<varname>v</varname>, <varname>q</varname>, <varname>Q</varname>, <varname>p</varname>, |
| 161 |
<varname>L</varname>, <varname>c</varname>, <varname>b</varname>, <varname>C</varname>, |
| 162 |
<varname>w</varname>, <varname>e</varname>. If this switch is used at least one |
| 163 |
<filename>tmpfiles.d/</filename> file (or <filename>-</filename> for standard input) must be |
| 164 |
specified on the command line or the invocation will be refused, for safety reasons (as otherwise |
| 165 |
much of the installed system files might be removed).</para> |
| 166 |
|
| 167 |
<para>The primary usecase for this option is to automatically remove files and directories that |
| 168 |
originally have been created on behalf of an installed package at package removal time.</para> |
| 169 |
|
| 170 |
<para>It is recommended to first run this command in combination with <option>--dry-run</option> |
| 171 |
(see below) to verify which files and directories will be deleted.</para> |
| 172 |
|
| 173 |
<para><emphasis>Warning!</emphasis> This is usually not the command you want! In most cases |
| 174 |
<option>--remove</option> is what you are looking for.</para> |
| 175 |
|
| 176 |
<xi:include href="version-info.xml" xpointer="v256"/></listitem> |
| 177 |
</varlistentry> |
| 178 |
|
| 179 |
<varlistentry> |
| 180 |
<term><option>--user</option></term> |
| 181 |
<listitem><para>Execute "user" configuration, i.e. <filename>tmpfiles.d/</filename> |
| 182 |
files in user configuration directories.</para> |
| 183 |
|
| 184 |
<xi:include href="version-info.xml" xpointer="v236"/></listitem> |
| 185 |
</varlistentry> |
| 186 |
|
| 187 |
<varlistentry> |
| 188 |
<term><option>--boot</option></term> |
| 189 |
<listitem><para>Also execute lines with an exclamation mark. Lines that are not safe to be executed |
| 190 |
on a running system may be marked in this way. <command>systemd-tmpfiles</command> is executed in |
| 191 |
early boot with <option>--boot</option> specified and will execute those lines. When invoked again |
| 192 |
later, it should be called without <option>--boot</option>.</para> |
| 193 |
|
| 194 |
<xi:include href="version-info.xml" xpointer="v209"/></listitem> |
| 195 |
</varlistentry> |
| 196 |
|
| 197 |
<varlistentry> |
| 198 |
<term><option>--graceful</option></term> |
| 199 |
<listitem><para>Ignore configuration lines pertaining to unknown users or groups. This option is |
| 200 |
intended to be used in early boot before all users or groups have been created.</para> |
| 201 |
|
| 202 |
<xi:include href="version-info.xml" xpointer="v254"/></listitem> |
| 203 |
</varlistentry> |
| 204 |
|
| 205 |
<varlistentry> |
| 206 |
<term><option>--dry-run</option></term> |
| 207 |
<listitem><para>Process the configuration and print what operations would be performed, but do not |
| 208 |
actually change anything in the file system.</para> |
| 209 |
|
| 210 |
<xi:include href="version-info.xml" xpointer="v256"/></listitem> |
| 211 |
</varlistentry> |
| 212 |
|
| 213 |
<varlistentry> |
| 214 |
<term><option>--inline</option></term> |
| 215 |
<listitem><para>Treat each positional argument as a separate configuration |
| 216 |
line instead of a file name.</para> |
| 217 |
|
| 218 |
<xi:include href="version-info.xml" xpointer="v261"/></listitem> |
| 219 |
</varlistentry> |
| 220 |
|
| 221 |
<varlistentry> |
| 222 |
<term><option>--prefix=<replaceable>path</replaceable></option></term> |
| 223 |
<listitem><para>Only apply rules with paths that start with |
| 224 |
the specified prefix. This option can be specified multiple |
| 225 |
times.</para> |
| 226 |
|
| 227 |
<xi:include href="version-info.xml" xpointer="v212"/></listitem> |
| 228 |
</varlistentry> |
| 229 |
|
| 230 |
<varlistentry> |
| 231 |
<term><option>--exclude-prefix=<replaceable>path</replaceable></option></term> |
| 232 |
<listitem><para>Ignore rules with paths that start with the |
| 233 |
specified prefix. This option can be specified multiple |
| 234 |
times.</para> |
| 235 |
|
| 236 |
<xi:include href="version-info.xml" xpointer="v207"/></listitem> |
| 237 |
</varlistentry> |
| 238 |
|
| 239 |
<varlistentry> |
| 240 |
<term><option>-E</option></term> |
| 241 |
<listitem><para>A shortcut for <literal>--exclude-prefix=/dev --exclude-prefix=/proc |
| 242 |
--exclude-prefix=/run --exclude-prefix=/sys</literal>, i.e. exclude the hierarchies typically backed |
| 243 |
by virtual or memory file systems. This is useful in combination with <option>--root=</option>, if |
| 244 |
the specified directory tree contains an OS tree without these virtual/memory file systems mounted |
| 245 |
in, as it is typically not desirable to create any files and directories below these subdirectories |
| 246 |
if they are supposed to be overmounted during runtime.</para> |
| 247 |
|
| 248 |
<xi:include href="version-info.xml" xpointer="v247"/></listitem> |
| 249 |
</varlistentry> |
| 250 |
|
| 251 |
<varlistentry> |
| 252 |
<term><option>--root=<replaceable>root</replaceable></option></term> |
| 253 |
<listitem><para>Takes a directory path as an argument. All paths will be prefixed with the given alternate |
| 254 |
<replaceable>root</replaceable> path, including config search paths.</para> |
| 255 |
|
| 256 |
<para>When this option is used, the libc Name Service Switch (NSS) is bypassed for resolving users |
| 257 |
and groups. Instead the files <filename>/etc/passwd</filename> and <filename>/etc/group</filename> |
| 258 |
inside the alternate root are read directly. This means that users/groups not listed in these files |
| 259 |
will not be resolved, i.e. LDAP NIS and other complex databases are not considered.</para> |
| 260 |
|
| 261 |
<para>Consider combining this with <option>-E</option> to ensure the invocation does not create files |
| 262 |
or directories below mount points in the OS image operated on that are typically overmounted during |
| 263 |
runtime.</para> |
| 264 |
|
| 265 |
<xi:include href="version-info.xml" xpointer="v212"/></listitem> |
| 266 |
</varlistentry> |
| 267 |
|
| 268 |
<varlistentry> |
| 269 |
<term><option>--image=<replaceable>image</replaceable></option></term> |
| 270 |
|
| 271 |
<listitem><para>Takes a path to a disk image file or block device node. If specified all operations |
| 272 |
are applied to file system in the indicated disk image. This is similar to <option>--root=</option> |
| 273 |
but operates on file systems stored in disk images or block devices. The disk image should either |
| 274 |
contain just a file system or a set of file systems within a GPT partition table, following the |
| 275 |
<ulink url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">UAPI.2 Discoverable Partitions |
| 276 |
Specification</ulink>. For further information on supported disk images, see |
| 277 |
<citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
| 278 |
switch of the same name.</para> |
| 279 |
|
| 280 |
<para>Implies <option>-E</option>.</para> |
| 281 |
|
| 282 |
<xi:include href="version-info.xml" xpointer="v247"/></listitem> |
| 283 |
</varlistentry> |
| 284 |
|
| 285 |
<xi:include href="standard-options.xml" xpointer="image-policy-open" /> |
| 286 |
|
| 287 |
<varlistentry> |
| 288 |
<term><option>--replace=<replaceable>PATH</replaceable></option></term> |
| 289 |
<listitem><para>When this option is given, one or more positional arguments |
| 290 |
must be specified. All configuration files found in the directories listed in |
| 291 |
<citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 292 |
will be read, and the configuration given on the command line will be |
| 293 |
handled instead of and with the same priority as the configuration file |
| 294 |
<replaceable>PATH</replaceable>.</para> |
| 295 |
|
| 296 |
<para>This option is intended to be used when package installation scripts |
| 297 |
are running and files belonging to that package are not yet available on |
| 298 |
disk, so their contents must be given on the command line, but the admin |
| 299 |
configuration might already exist and should be given higher priority. |
| 300 |
</para> |
| 301 |
|
| 302 |
<xi:include href="version-info.xml" xpointer="v238"/></listitem> |
| 303 |
</varlistentry> |
| 304 |
|
| 305 |
<xi:include href="standard-options.xml" xpointer="cat-config" /> |
| 306 |
<xi:include href="standard-options.xml" xpointer="tldr" /> |
| 307 |
<xi:include href="standard-options.xml" xpointer="no-pager" /> |
| 308 |
<xi:include href="standard-options.xml" xpointer="help" /> |
| 309 |
<xi:include href="standard-options.xml" xpointer="version" /> |
| 310 |
</variablelist> |
| 311 |
|
| 312 |
<para>It is possible to combine <option>--create</option>, <option>--clean</option>, and <option>--remove</option> |
| 313 |
in one invocation (in which case removal and cleanup are executed before creation of new files). For example, |
| 314 |
during boot the following command line is executed to ensure that all temporary and volatile directories are |
| 315 |
removed and created according to the configuration file:</para> |
| 316 |
|
| 317 |
<programlisting>systemd-tmpfiles --remove --create</programlisting> |
| 318 |
</refsect1> |
| 319 |
|
| 320 |
<refsect1> |
| 321 |
<title>Credentials</title> |
| 322 |
|
| 323 |
<para><command>systemd-tmpfiles</command> supports the service credentials logic as implemented by |
| 324 |
<varname>ImportCredential=</varname>/<varname>LoadCredential=</varname>/<varname>SetCredential=</varname> |
| 325 |
(see <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for |
| 326 |
details). The following credentials are used when passed in:</para> |
| 327 |
|
| 328 |
<variablelist class='system-credentials'> |
| 329 |
<varlistentry> |
| 330 |
<term><varname>tmpfiles.extra</varname></term> |
| 331 |
|
| 332 |
<listitem><para> The contents of this credential may contain additional lines to operate on. The |
| 333 |
credential contents should follow the same format as any other <filename>tmpfiles.d/</filename> |
| 334 |
drop-in configuration file. If this credential is passed it is processed after all of the drop-in |
| 335 |
files read from the file system. The lines in the credential can hence augment existing lines of the |
| 336 |
OS, but not override them.</para> |
| 337 |
|
| 338 |
<xi:include href="version-info.xml" xpointer="v252"/></listitem> |
| 339 |
</varlistentry> |
| 340 |
</variablelist> |
| 341 |
|
| 342 |
<para>Note that by default the <filename>systemd-tmpfiles-setup.service</filename> unit file (and related |
| 343 |
unit files) is set up to inherit the <literal>tmpfiles.extra</literal> credential from the service |
| 344 |
manager.</para> |
| 345 |
</refsect1> |
| 346 |
|
| 347 |
<refsect1> |
| 348 |
<title>Environment</title> |
| 349 |
|
| 350 |
<variablelist class='environment-variables'> |
| 351 |
<xi:include href="common-variables.xml" xpointer="log-level" /> |
| 352 |
<xi:include href="common-variables.xml" xpointer="log-color" /> |
| 353 |
<xi:include href="common-variables.xml" xpointer="log-time" /> |
| 354 |
<xi:include href="common-variables.xml" xpointer="log-location" /> |
| 355 |
<xi:include href="common-variables.xml" xpointer="log-target" /> |
| 356 |
<xi:include href="common-variables.xml" xpointer="pager" /> |
| 357 |
<xi:include href="common-variables.xml" xpointer="less" /> |
| 358 |
<xi:include href="common-variables.xml" xpointer="lesscharset" /> |
| 359 |
<xi:include href="common-variables.xml" xpointer="lesssecure" /> |
| 360 |
<xi:include href="common-variables.xml" xpointer="colors" /> |
| 361 |
<xi:include href="common-variables.xml" xpointer="urlify" /> |
| 362 |
</variablelist> |
| 363 |
</refsect1> |
| 364 |
|
| 365 |
<refsect1> |
| 366 |
<title>Unprivileged --cleanup operation</title> |
| 367 |
|
| 368 |
<para><command>systemd-tmpfiles</command> tries to avoid changing |
| 369 |
the access and modification times on the directories it accesses, |
| 370 |
which requires <constant>CAP_FOWNER</constant> privileges. When |
| 371 |
running as non-root, directories which are checked for files to |
| 372 |
clean up will have their access time bumped, which might prevent |
| 373 |
their cleanup. |
| 374 |
</para> |
| 375 |
</refsect1> |
| 376 |
|
| 377 |
<refsect1> |
| 378 |
<title>Exit status</title> |
| 379 |
|
| 380 |
<para>On success, 0 is returned. If the configuration was syntactically invalid (syntax errors, missing |
| 381 |
arguments, …), so some lines had to be ignored, but no other errors occurred, <constant>65</constant> is |
| 382 |
returned (<constant>EX_DATAERR</constant> from <filename>/usr/include/sysexits.h</filename>). If the |
| 383 |
configuration was syntactically valid, but could not be executed (lack of permissions, creation of files |
| 384 |
in missing directories, invalid contents when writing to <filename>/sys/</filename> values, …), |
| 385 |
<constant>73</constant> is returned (<constant>EX_CANTCREAT</constant> from |
| 386 |
<filename>/usr/include/sysexits.h</filename>). Otherwise, <constant>1</constant> is returned |
| 387 |
(<constant>EXIT_FAILURE</constant> from <filename>/usr/include/stdlib.h</filename>).</para> |
| 388 |
|
| 389 |
<para>Note: when creating items, if the target already exists, but is of the wrong type or otherwise does |
| 390 |
not match the requested state, and forced operation has not been requested with <literal>+</literal>, |
| 391 |
a message is emitted, but the failure is otherwise ignored.</para> |
| 392 |
</refsect1> |
| 393 |
|
| 394 |
<refsect1> |
| 395 |
<title>See Also</title> |
| 396 |
<para><simplelist type="inline"> |
| 397 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 398 |
<member><citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 399 |
</simplelist></para> |
| 400 |
</refsect1> |
| 401 |
|
| 402 |
</refentry> |