1FILE-HIERARCHY(7) file-hierarchy FILE-HIERARCHY(7)
2
3
4
6 file-hierarchy - File system hierarchy overview
7
9 Operating systems using the systemd(1) system and service manager are
10 organized based on a file system hierarchy inspired by UNIX, more
11 specifically the hierarchy described in the File System Hierarchy[1]
12 specification and hier(7). This manual page describes a more minimal,
13 modernized subset of these specifications that defines more strictly
14 the suggestions and restrictions systemd makes on the file system
15 hierarchy.
16
17 Many of the paths described here are queriable with the systemd-path(1)
18 tool.
19
21 /
22 The file system root. Usually writable, but this is not required.
23 Possibly a temporary file system ("tmpfs"). Not shared with other
24 hosts (unless read-only).
25
26 /boot
27 The boot partition used for bringing up the system. On EFI systems
28 this is possibly the EFI System Partition, also see systemd-efi-
29 boot-generator(8). This directory is usually strictly local to the
30 host, and should be considered read-only, except when a new kernel
31 or boot loader is installed. This directory only exists on systems
32 that run on physical or emulated hardware that requires boot
33 loaders.
34
35 /etc
36 System-specific configuration. This directory may or may not be
37 read-only. Frequently, this directory is pre-populated with
38 vendor-supplied configuration files, but applications should not
39 make assumptions about this directory being fully populated or
40 populated at all, and should fall back to defaults if configuration
41 is missing.
42
43 /home
44 The location for normal user's home directories. Possibly shared
45 with other systems, and never read-only. This directory should only
46 be used for normal users, never for system users. This directory
47 and possibly the directories contained within it might only become
48 available or writable in late boot or even only after user
49 authentication. This directory might be placed on
50 limited-functionality network file systems, hence applications
51 should not assume the full set of file API is available on this
52 directory. Applications should generally not reference this
53 directory directly, but via the per-user $HOME environment
54 variable, or via the home directory field of the user database.
55
56 /root
57 The home directory of the root user. The root user's home directory
58 is located outside of /home in order to make sure the root user may
59 log in even without /home being available and mounted.
60
61 /srv
62 The place to store general server payload, managed by the
63 administrator. No restrictions are made how this directory is
64 organized internally. Generally writable, and possibly shared among
65 systems. This directory might become available or writable only
66 very late during boot.
67
68 /tmp
69 The place for small temporary files. This directory is usually
70 mounted as a "tmpfs" instance, and should hence not be used for
71 larger files. (Use /var/tmp for larger files.) Since the directory
72 is accessible to other users of the system it is essential that
73 this directory is only written to with the mkstemp(3), mkdtemp(3)
74 and related calls. This directory is usually flushed at boot-up.
75 Also, files that are not accessed within a certain time are usually
76 automatically deleted. If applications find the environment
77 variable $TMPDIR set they should prefer using the directory
78 specified in it over directly referencing /tmp (see environ(7) and
79 IEEE Std 1003.1[2] for details).
80
82 /run
83 A "tmpfs" file system for system packages to place runtime data in.
84 This directory is flushed on boot, and generally writable for
85 privileged programs only. Always writable.
86
87 /run/log
88 Runtime system logs. System components may place private logs in
89 this directory. Always writable, even when /var/log might not be
90 accessible yet.
91
92 /run/user
93 Contains per-user runtime directories, each usually individually
94 mounted "tmpfs" instances. Always writable, flushed at each reboot
95 and when the user logs out. User code should not reference this
96 directory directly, but via the $XDG_RUNTIME_DIR environment
97 variable, as documented in the XDG Base Directory Specification[3].
98
100 /usr
101 Vendor-supplied operating system resources. Usually read-only, but
102 this is not required. Possibly shared between multiple hosts. This
103 directory should not be modified by the administrator, except when
104 installing or removing vendor-supplied packages.
105
106 /usr/bin
107 Binaries and executables for user commands, that shall appear in
108 the $PATH search path. It is recommended not to place binaries in
109 this directory that are not useful for invocation from a shell
110 (such as daemon binaries); these should be placed in a subdirectory
111 of /usr/lib instead.
112
113 /usr/include
114 C and C++ API header files of system libraries.
115
116 /usr/lib
117 Static, private vendor data that is compatible with all
118 architectures (though not necessarily architecture-independent).
119 Note that this includes internal executables or other binaries that
120 are not regularly invoked from a shell. Such binaries may be for
121 any architecture supported by the system. Do not place public
122 libraries in this directory, use $libdir (see below), instead.
123
124 /usr/lib/arch-id
125 Location for placing dynamic libraries, also called $libdir. The
126 architecture identifier to use is defined on Multiarch Architecture
127 Specifiers (Tuples)[4] list. Legacy locations of $libdir are
128 /usr/lib, /usr/lib64. This directory should not be used for
129 package-specific data, unless this data is architecture-dependent,
130 too. To query $libdir for the primary architecture of the system,
131 invoke:
132
133 # pkg-config --variable=libdir
134 systemd
135
136 or
137
138 # systemd-path
139 system-library-arch
140
141
142 /usr/share
143 Resources shared between multiple packages, such as documentation,
144 man pages, time zone information, fonts and other resources.
145 Usually, the precise location and format of files stored below this
146 directory is subject to specifications that ensure
147 interoperability.
148
149 /usr/share/doc
150 Documentation for the operating system or system packages.
151
152 /usr/share/factory/etc
153 Repository for vendor-supplied default configuration files. This
154 directory should be populated with pristine vendor versions of all
155 configuration files that may be placed in /etc. This is useful to
156 compare the local configuration of a system with vendor defaults
157 and to populate the local configuration with defaults.
158
159 /usr/share/factory/var
160 Similar to /usr/share/factory/etc but for vendor versions of files
161 in the variable, persistent data directory /var.
162
164 /var
165 Persistent, variable system data. Must be writable. This directory
166 might be pre-populated with vendor-supplied data, but applications
167 should be able to reconstruct necessary files and directories in
168 this subhierarchy should they be missing, as the system might start
169 up without this directory being populated. Persistency is
170 recommended, but optional, to support ephemeral systems. This
171 directory might become available or writable only very late during
172 boot. Components that are required to operate during early boot
173 hence shall not unconditionally rely on this directory.
174
175 /var/cache
176 Persistent system cache data. System components may place
177 non-essential data in this directory. Flushing this directory
178 should have no effect on operation of programs, except for
179 increased runtimes necessary to rebuild these caches.
180
181 /var/lib
182 Persistent system data. System components may place private data in
183 this directory.
184
185 /var/log
186 Persistent system logs. System components may place private logs in
187 this directory, though it is recommended to do most logging via the
188 syslog(3) and sd_journal_print(3) calls.
189
190 /var/spool
191 Persistent system spool data, such as printer or mail queues.
192
193 /var/tmp
194 The place for larger and persistent temporary files. In contrast to
195 /tmp this directory is usually mounted from a persistent physical
196 file system and can thus accept larger files. (Use /tmp for smaller
197 files.) This directory is generally not flushed at boot-up, but
198 time-based cleanup of files that have not been accessed for a
199 certain time is applied. The same security restrictions as with
200 /tmp apply, and hence only mkstemp(3), mkdtemp(3) or similar calls
201 should be used to make use of this directory. If applications find
202 the environment variable $TMPDIR set they should prefer using the
203 directory specified in it over directly referencing /var/tmp (see
204 environ(7) for details).
205
207 /dev
208 The root directory for device nodes. Usually this directory is
209 mounted as a "devtmpfs" instance, but might be of a different type
210 in sandboxed/containerized setups. This directory is managed
211 jointly by the kernel and systemd-udevd(8), and should not be
212 written to by other components. A number of special purpose virtual
213 file systems might be mounted below this directory.
214
215 /dev/shm
216 Place for POSIX shared memory segments, as created via shm_open(3).
217 This directory is flushed on boot, and is a "tmpfs" file system.
218 Since all users have write access to this directory, special care
219 should be taken to avoid name clashes and vulnerabilities. For
220 normal users, shared memory segments in this directory are usually
221 deleted when the user logs out. Usually it is a better idea to use
222 memory mapped files in /run (for system programs) or
223 $XDG_RUNTIME_DIR (for user programs) instead of POSIX shared memory
224 segments, since those directories are not world-writable and hence
225 not vulnerable to security-sensitive name clashes.
226
227 /proc
228 A virtual kernel file system exposing the process list and other
229 functionality. This file system is mostly an API to interface with
230 the kernel and not a place where normal files may be stored. For
231 details, see proc(5). A number of special purpose virtual file
232 systems might be mounted below this directory.
233
234 /proc/sys
235 A hierarchy below /proc that exposes a number of kernel tunables.
236 The primary way to configure the settings in this API file tree is
237 via sysctl.d(5) files. In sandboxed/containerized setups this
238 directory is generally mounted read-only.
239
240 /sys
241 A virtual kernel file system exposing discovered devices and other
242 functionality. This file system is mostly an API to interface with
243 the kernel and not a place where normal files may be stored. In
244 sandboxed/containerized setups this directory is generally mounted
245 read-only. A number of special purpose virtual file systems might
246 be mounted below this directory.
247
249 /bin, /sbin, /usr/sbin
250 These compatibility symlinks point to /usr/bin, ensuring that
251 scripts and binaries referencing these legacy paths correctly find
252 their binaries.
253
254 /lib
255 This compatibility symlink points to /usr/lib, ensuring that
256 programs referencing this legacy path correctly find their
257 resources.
258
259 /lib64
260 On some architecture ABIs this compatibility symlink points to
261 $libdir, ensuring that binaries referencing this legacy path
262 correctly find their dynamic loader. This symlink only exists on
263 architectures whose ABI places the dynamic loader in this path.
264
265 /var/run
266 This compatibility symlink points to /run, ensuring that programs
267 referencing this legacy path correctly find their runtime data.
268
270 User applications may want to place files and directories in the user's
271 home directory. They should follow the following basic structure. Note
272 that some of these directories are also standardized (though more
273 weakly) by the XDG Base Directory Specification[3]. Additional
274 locations for high-level user resources are defined by
275 xdg-user-dirs[5].
276
277 ~/.cache
278 Persistent user cache data. User programs may place non-essential
279 data in this directory. Flushing this directory should have no
280 effect on operation of programs, except for increased runtimes
281 necessary to rebuild these caches. If an application finds
282 $XDG_CACHE_HOME set is should use the directory specified in it
283 instead of this directory.
284
285 ~/.config
286 Application configuration and state. When a new user is created
287 this directory will be empty or not exist at all. Applications
288 should fall back to defaults should their configuration or state in
289 this directory be missing. If an application finds $XDG_CONFIG_HOME
290 set is should use the directory specified in it instead of this
291 directory.
292
293 ~/.local/bin
294 Executables that shall appear in the user's $PATH search path. It
295 is recommended not to place executables in this directory that are
296 not useful for invocation from a shell; these should be placed in a
297 subdirectory of ~/.local/lib instead. Care should be taken when
298 placing architecture-dependent binaries in this place which might
299 be problematic if the home directory is shared between multiple
300 hosts with different architectures.
301
302 ~/.local/lib
303 Static, private vendor data that is compatible with all
304 architectures.
305
306 ~/.local/lib/arch-id
307 Location for placing public dynamic libraries. The architecture
308 identifier to use, is defined on Multiarch Architecture Specifiers
309 (Tuples)[4] list.
310
311 ~/.local/share
312 Resources shared between multiple packages, such as fonts or
313 artwork. Usually, the precise location and format of files stored
314 below this directory is subject to specifications that ensure
315 interoperability. If an application finds $XDG_DATA_HOME set is
316 should use the directory specified in it instead of this directory.
317
319 Unprivileged processes generally lack write access to most of the
320 hierarchy.
321
322 The exceptions for normal users are /tmp, /var/tmp, /dev/shm, as well
323 as the home directory $HOME (usually found below /home) and the runtime
324 directory $XDG_RUNTIME_DIR (found below /run/user) of the user, which
325 are all writable.
326
327 For unprivileged system processes only /tmp, /var/tmp and /dev/shm are
328 writable. If an unprivileged system process needs a private, writable
329 directory in /var or /run, it is recommended to either create it before
330 dropping privileges in the daemon code, to create it via tmpfiles.d(5)
331 fragments during boot, or via the RuntimeDirectory= directive of
332 service units (see systemd.unit(5) for details).
333
335 Unix file systems support different types of file nodes, including
336 regular files, directories, symlinks, character and block device nodes,
337 sockets and FIFOs.
338
339 It is strongly recommended that /dev is the only location below which
340 device nodes shall be placed. Similar, /run shall be the only location
341 to place sockets and FIFOs. Regular files, directories and symlinks may
342 be used in all directories.
343
345 Developers of system packages should follow strict rules when placing
346 their own files in the file system. The following table lists
347 recommended locations for specific types of files supplied by the
348 vendor.
349
350 Table 1. System Package Vendor Files Locations
351 ┌─────────────────────────┬────────────────────────────┐
352 │Directory │ Purpose │
353 ├─────────────────────────┼────────────────────────────┤
354 │/usr/bin │ Package executables that │
355 │ │ shall appear in the $PATH │
356 │ │ executable search path, │
357 │ │ compiled for any of the │
358 │ │ supported architectures │
359 │ │ compatible with the │
360 │ │ operating system. It is │
361 │ │ not recommended to place │
362 │ │ internal binaries or │
363 │ │ binaries that are not │
364 │ │ commonly invoked from the │
365 │ │ shell in this directory, │
366 │ │ such as daemon binaries. │
367 │ │ As this directory is │
368 │ │ shared with most other │
369 │ │ packages of the system │
370 │ │ special care should be │
371 │ │ taken to pick unique names │
372 │ │ for files placed here, │
373 │ │ that are unlikely to clash │
374 │ │ with other package's │
375 │ │ files. │
376 ├─────────────────────────┼────────────────────────────┤
377 │/usr/lib/arch-id │ Public shared libraries of │
378 │ │ the package. As above, be │
379 │ │ careful with using too │
380 │ │ generic names, and pick │
381 │ │ unique names for your │
382 │ │ libraries to place here to │
383 │ │ avoid name clashes. │
384 ├─────────────────────────┼────────────────────────────┤
385 │/usr/lib/package │ Private, static vendor │
386 │ │ resources of the package, │
387 │ │ including private binaries │
388 │ │ and libraries, or any │
389 │ │ other kind of read-only │
390 │ │ vendor data. │
391 ├─────────────────────────┼────────────────────────────┤
392 │/usr/lib/arch-id/package │ Private other vendor │
393 │ │ resources of the package │
394 │ │ that are │
395 │ │ architecture-specific and │
396 │ │ cannot be shared between │
397 │ │ architectures. Note that │
398 │ │ this generally does not │
399 │ │ include private │
400 │ │ executables since binaries │
401 │ │ of a specific architecture │
402 │ │ may be freely invoked from │
403 │ │ any other supported system │
404 │ │ architecture. │
405 ├─────────────────────────┼────────────────────────────┤
406 │/usr/include/package │ Public C/C++ APIs of │
407 │ │ public shared libraries of │
408 │ │ the package. │
409 └─────────────────────────┴────────────────────────────┘
410
411 Additional static vendor files may be installed in the /usr/share
412 hierarchy, to the locations defined by the various relevant
413 specifications.
414
415 During runtime and for local configuration and state additional
416 directories are defined:
417
418 Table 2. System Package Variable Files Locations
419 ┌───────────────────┬────────────────────────────┐
420 │Directory │ Purpose │
421 ├───────────────────┼────────────────────────────┤
422 │/etc/package │ System-specific │
423 │ │ configuration for the │
424 │ │ package. It is recommended │
425 │ │ to default to safe │
426 │ │ fallbacks if this │
427 │ │ configuration is missing, │
428 │ │ if this is possible. │
429 │ │ Alternatively, a │
430 │ │ tmpfiles.d(5) fragment may │
431 │ │ be used to copy or symlink │
432 │ │ the necessary files and │
433 │ │ directories from │
434 │ │ /usr/share/factory during │
435 │ │ boot, via the "L" or "C" │
436 │ │ directives. │
437 ├───────────────────┼────────────────────────────┤
438 │/run/package │ Runtime data for the │
439 │ │ package. Packages must be │
440 │ │ able to create the │
441 │ │ necessary subdirectories │
442 │ │ in this tree on their own, │
443 │ │ since the directory is │
444 │ │ flushed automatically on │
445 │ │ boot. Alternatively, a │
446 │ │ tmpfiles.d(5) fragment may │
447 │ │ be used to create the │
448 │ │ necessary directories │
449 │ │ during boot. │
450 │ │ Alternatively, the │
451 │ │ RuntimeDirectory= │
452 │ │ directive of service units │
453 │ │ may be used (see │
454 │ │ systemd.unit(5) for │
455 │ │ details.) │
456 ├───────────────────┼────────────────────────────┤
457 │/run/log/package │ Runtime log data for the │
458 │ │ package. As above, the │
459 │ │ package needs to make sure │
460 │ │ to create this directory │
461 │ │ if necessary, as it will │
462 │ │ be flushed on every boot. │
463 ├───────────────────┼────────────────────────────┤
464 │/var/cache/package │ Persistent cache data of │
465 │ │ the package. If this │
466 │ │ directory is flushed the │
467 │ │ application should work │
468 │ │ correctly on next │
469 │ │ invocation, though │
470 │ │ possibly slowed down due │
471 │ │ to the need to rebuild any │
472 │ │ local cache files. The │
473 │ │ application must be │
474 │ │ capable of recreating this │
475 │ │ directory should it be │
476 │ │ missing and necessary. │
477 ├───────────────────┼────────────────────────────┤
478 │/var/lib/package │ Persistent private data of │
479 │ │ the package. This is the │
480 │ │ primary place to put │
481 │ │ persistent data that does │
482 │ │ not fall into the other │
483 │ │ categories listed. │
484 │ │ Packages should be able to │
485 │ │ create the necessary │
486 │ │ subdirectories in this │
487 │ │ tree on their own, since │
488 │ │ the directory might be │
489 │ │ missing on boot. │
490 │ │ Alternatively, a │
491 │ │ tmpfiles.d(5) fragment may │
492 │ │ be used to create the │
493 │ │ necessary directories │
494 │ │ during boot. │
495 ├───────────────────┼────────────────────────────┤
496 │/var/log/package │ Persistent log data of the │
497 │ │ package. As above, the │
498 │ │ package should make sure │
499 │ │ to create this directory │
500 │ │ if necessary, as it might │
501 │ │ be missing. │
502 ├───────────────────┼────────────────────────────┤
503 │/var/spool/package │ Persistent spool/queue │
504 │ │ data of the package. As │
505 │ │ above, the package should │
506 │ │ make sure to create this │
507 │ │ directory if necessary, as │
508 │ │ it might be missing. │
509 └───────────────────┴────────────────────────────┘
510
512 Programs running in user context should follow strict rules when
513 placing their own files in the user's home directory. The following
514 table lists recommended locations in the home directory for specific
515 types of files supplied by the vendor if the application is installed
516 in the home directory. (Note however, that user applications installed
517 system-wide should follow the rules outlined above regarding placing
518 vendor files.)
519
520 Table 3. User Package Vendor File Locations
521 ┌─────────────────────────────┬────────────────────────────┐
522 │Directory │ Purpose │
523 ├─────────────────────────────┼────────────────────────────┤
524 │~/.local/bin │ Package executables that │
525 │ │ shall appear in the $PATH │
526 │ │ executable search path. It │
527 │ │ is not recommended to │
528 │ │ place internal executables │
529 │ │ or executables that are │
530 │ │ not commonly invoked from │
531 │ │ the shell in this │
532 │ │ directory, such as daemon │
533 │ │ executables. As this │
534 │ │ directory is shared with │
535 │ │ most other packages of the │
536 │ │ user special care should │
537 │ │ be taken to pick unique │
538 │ │ names for files placed │
539 │ │ here, that are unlikely to │
540 │ │ clash with other package's │
541 │ │ files. │
542 ├─────────────────────────────┼────────────────────────────┤
543 │~/.local/lib/arch-id │ Public shared libraries of │
544 │ │ the package. As above, be │
545 │ │ careful with using too │
546 │ │ generic names, and pick │
547 │ │ unique names for your │
548 │ │ libraries to place here to │
549 │ │ avoid name clashes. │
550 ├─────────────────────────────┼────────────────────────────┤
551 │~/.local/lib/package │ Private, static vendor │
552 │ │ resources of the package, │
553 │ │ compatible with any │
554 │ │ architecture, or any other │
555 │ │ kind of read-only vendor │
556 │ │ data. │
557 ├─────────────────────────────┼────────────────────────────┤
558 │~/.local/lib/arch-id/package │ Private other vendor │
559 │ │ resources of the package │
560 │ │ that are │
561 │ │ architecture-specific and │
562 │ │ cannot be shared between │
563 │ │ architectures. │
564 └─────────────────────────────┴────────────────────────────┘
565
566 Additional static vendor files may be installed in the ~/.local/share
567 hierarchy, to the locations defined by the various relevant
568 specifications.
569
570 During runtime and for local configuration and state additional
571 directories are defined:
572
573 Table 4. User Package Variable File Locations
574 ┌─────────────────────────┬────────────────────────────┐
575 │Directory │ Purpose │
576 ├─────────────────────────┼────────────────────────────┤
577 │~/.config/package │ User-specific │
578 │ │ configuration and state │
579 │ │ for the package. It is │
580 │ │ required to default to │
581 │ │ safe fallbacks if this │
582 │ │ configuration is missing. │
583 ├─────────────────────────┼────────────────────────────┤
584 │$XDG_RUNTIME_DIR/package │ User runtime data for the │
585 │ │ package. │
586 ├─────────────────────────┼────────────────────────────┤
587 │~/.cache/package │ Persistent cache data of │
588 │ │ the package. If this │
589 │ │ directory is flushed the │
590 │ │ application should work │
591 │ │ correctly on next │
592 │ │ invocation, though │
593 │ │ possibly slowed down due │
594 │ │ to the need to rebuild any │
595 │ │ local cache files. The │
596 │ │ application must be │
597 │ │ capable of recreating this │
598 │ │ directory should it be │
599 │ │ missing and necessary. │
600 └─────────────────────────┴────────────────────────────┘
601
603 systemd(1), hier(7), systemd-path(1), systemd-efi-boot-generator(8),
604 sysctl.d(5), tmpfiles.d(5), pkg-config(1), systemd.unit(5)
605
607 1. File System Hierarchy
608 http://refspecs.linuxfoundation.org/FHS_2.3/fhs-2.3.html
609
610 2. IEEE Std 1003.1
611 http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
612
613 3. XDG Base Directory Specification
614 http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
615
616 4. Multiarch Architecture Specifiers (Tuples)
617 https://wiki.debian.org/Multiarch/Tuples
618
619 5. xdg-user-dirs
620 http://www.freedesktop.org/wiki/Software/xdg-user-dirs/
621
622
623
624systemd 219 FILE-HIERARCHY(7)