file-hierarchy - File system hierarchy overview
Operating systems using the systemd(1) system and service manager are organized based on a file system hierarchy inspired by UNIX, more specifically the hierarchy described in the File System Hierarchy  specification and hier(7). This manual page describes a more minimal, modernized subset of these specifications that defines more strictly the suggestions and restrictions systemd makes on the file system hierarchy.
Many of the paths described here can be queried with the systemd-path(1) tool.
The file system root. Usually writable, but this is not required. Possibly a temporary file system ("tmpfs"). Not shared with other hosts (unless read-only).
The boot partition used for bringing up the system. On EFI systems, this is possibly the EFI System Partition, also see systemd-gpt-auto-generator(8). This directory is usually strictly local to the host, and should be considered read-only, except when a new kernel or boot loader is installed. This directory only exists on systems that run on physical or emulated hardware that requires boot loaders.
System-specific configuration. This directory may or may not be read-only. Frequently, this directory is pre-populated with vendor-supplied configuration files, but applications should not make assumptions about this directory being fully populated or populated at all, and should fall back to defaults if configuration is missing.
The location for normal user's home directories. Possibly shared with other systems, and never read-only. This directory should only be used for normal users, never for system users. This directory and possibly the directories contained within it might only become available or writable in late boot or even only after user authentication. This directory might be placed on limited-functionality network file systems, hence applications should not assume the full set of file API is available on this directory. Applications should generally not reference this directory directly, but via the per-user $HOME environment variable, or via the home directory field of the user database.
The home directory of the root user. The root user's home directory is located outside of /home in order to make sure the root user may log in even without /home being available and mounted.
The place to store general server payload, managed by the administrator. No restrictions are made how this directory is organized internally. Generally writable, and possibly shared among systems. This directory might become available or writable only very late during boot.
The place for small temporary files. This directory is usually mounted as a "tmpfs" instance, and should hence not be used for larger files. (Use /var/tmp for larger files.) Since the directory is accessible to other users of the system, it is essential that this directory is only written to with the mkstemp(3), mkdtemp(3) and related calls. This directory is usually flushed at boot-up. Also, files that are not accessed within a certain time are usually automatically deleted. If applications find the environment variable $TMPDIR set, they should prefer using the directory specified in it over directly referencing /tmp (see environ(7) and IEEE Std 1003.1  for details).
A "tmpfs" file system for system packages to place runtime data in. This directory is flushed on boot, and generally writable for privileged programs only. Always writable.
Runtime system logs. System components may place private logs in this directory. Always writable, even when /var/log might not be accessible yet.
Contains per-user runtime directories, each usually individually mounted "tmpfs" instances. Always writable, flushed at each reboot and when the user logs out. User code should not reference this directory directly, but via the $XDG_RUNTIME_DIR environment variable, as documented in the XDG Base Directory Specification  .
Vendor-supplied operating system resources. Usually read-only, but this is not required. Possibly shared between multiple hosts. This directory should not be modified by the administrator, except when installing or removing vendor-supplied packages.
Binaries and executables for user commands that shall appear in the $PATH search path. It is recommended not to place binaries in this directory that are not useful for invocation from a shell (such as daemon binaries); these should be placed in a subdirectory of /usr/lib instead.
C and C++ API header files of system libraries.
Static, private vendor data that is compatible with all architectures (though not necessarily architecture-independent). Note that this includes internal executables or other binaries that are not regularly invoked from a shell. Such binaries may be for any architecture supported by the system. Do not place public libraries in this directory, use $libdir (see below), instead.
Location for placing dynamic libraries into, also called $libdir. The architecture identifier to use is defined on Multiarch Architecture Specifiers (Tuples)  list. Legacy locations of $libdir are /lib, /lib64. This directory should not be used for package-specific data, unless this data is architecture-dependent, too. To query $libdir for the primary architecture of the system, invoke:
# systemd-path system-library-arch
Resources shared between multiple packages, such as documentation, man pages, time zone information, fonts and other resources. Usually, the precise location and format of files stored below this directory is subject to specifications that ensure interoperability.
Documentation for the operating system or system packages.
Repository for vendor-supplied default configuration files. This directory should be populated with pristine vendor versions of all configuration files that may be placed in /etc. This is useful to compare the local configuration of a system with vendor defaults and to populate the local configuration with defaults.
Similar to /usr/share/factory/etc, but for vendor versions of files in the variable, persistent data directory /var.
Persistent, variable system data. Must be writable. This directory might be pre-populated with vendor-supplied data, but applications should be able to reconstruct necessary files and directories in this subhierarchy should they be missing, as the system might start up without this directory being populated. Persistency is recommended, but optional, to support ephemeral systems. This directory might become available or writable only very late during boot. Components that are required to operate during early boot hence shall not unconditionally rely on this directory.
Persistent system cache data. System components may place non-essential data in this directory. Flushing this directory should have no effect on operation of programs, except for increased runtimes necessary to rebuild these caches.
Persistent system data. System components may place private data in this directory.
Persistent system logs. System components may place private logs in this directory, though it is recommended to do most logging via the syslog(3) and sd_journal_print(3) calls.
Persistent system spool data, such as printer or mail queues.
The place for larger and persistent temporary files. In contrast to /tmp, this directory is usually mounted from a persistent physical file system and can thus accept larger files. (Use /tmp for smaller files.) This directory is generally not flushed at boot-up, but time-based cleanup of files that have not been accessed for a certain time is applied. The same security restrictions as with /tmp apply, and hence only mkstemp(3), mkdtemp(3) or similar calls should be used to make use of this directory. If applications find the environment variable $TMPDIR set, they should prefer using the directory specified in it over directly referencing /var/tmp (see environ(7) for details).
The root directory for device nodes. Usually, this directory is mounted as a "devtmpfs" instance, but might be of a different type in sandboxed/containerized setups. This directory is managed jointly by the kernel and systemd-udevd(8), and should not be written to by other components. A number of special purpose virtual file systems might be mounted below this directory.
Place for POSIX shared memory segments, as created via shm_open(3). This directory is flushed on boot, and is a "tmpfs" file system. Since all users have write access to this directory, special care should be taken to avoid name clashes and vulnerabilities. For normal users, shared memory segments in this directory are usually deleted when the user logs out. Usually, it is a better idea to use memory mapped files in /run (for system programs) or $XDG_RUNTIME_DIR (for user programs) instead of POSIX shared memory segments, since these directories are not world-writable and hence not vulnerable to security-sensitive name clashes.
A virtual kernel file system exposing the process list and other functionality. This file system is mostly an API to interface with the kernel and not a place where normal files may be stored. For details, see proc(5). A number of special purpose virtual file systems might be mounted below this directory.
A hierarchy below /proc that exposes a number of kernel tunables. The primary way to configure the settings in this API file tree is via sysctl.d(5) files. In sandboxed/containerized setups, this directory is generally mounted read-only.
A virtual kernel file system exposing discovered devices and other functionality. This file system is mostly an API to interface with the kernel and not a place where normal files may be stored. In sandboxed/containerized setups, this directory is generally mounted read-only. A number of special purpose virtual file systems might be mounted below this directory.
/bin, /sbin, /usr/sbin
These compatibility symlinks point to /usr/bin, ensuring that scripts and binaries referencing these legacy paths correctly find their binaries.
This compatibility symlink points to /lib, ensuring that programs referencing this legacy path correctly find their resources.
On some architecture ABIs, this compatibility symlink points to $libdir, ensuring that binaries referencing this legacy path correctly find their dynamic loader. This symlink only exists on architectures whose ABI places the dynamic loader in this path.
This compatibility symlink points to /run, ensuring that programs referencing this legacy path correctly find their runtime data.
User applications may want to place files and directories in the user's home directory. They should follow the following basic structure. Note that some of these directories are also standardized (though more weakly) by the XDG Base Directory Specification  . Additional locations for high-level user resources are defined by xdg-user-dirs  .
Persistent user cache data. User programs may place non-essential data in this directory. Flushing this directory should have no effect on operation of programs, except for increased runtimes necessary to rebuild these caches. If an application finds $XDG_CACHE_HOME set, it should use the directory specified in it instead of this directory.
Application configuration and state. When a new user is created, this directory will be empty or not exist at all. Applications should fall back to defaults should their configuration or state in this directory be missing. If an application finds $XDG_CONFIG_HOME set, it should use the directory specified in it instead of this directory.
Executables that shall appear in the user's $PATH search path. It is recommended not to place executables in this directory that are not useful for invocation from a shell; these should be placed in a subdirectory of ~/.local/lib instead. Care should be taken when placing architecture-dependent binaries in this place, which might be problematic if the home directory is shared between multiple hosts with different architectures.
Static, private vendor data that is compatible with all architectures.
Location for placing public dynamic libraries. The architecture identifier to use is defined on Multiarch Architecture Specifiers (Tuples)  list.
Resources shared between multiple packages, such as fonts or artwork. Usually, the precise location and format of files stored below this directory is subject to specifications that ensure interoperability. If an application finds $XDG_DATA_HOME set, it should use the directory specified in it instead of this directory.
Unprivileged processes generally lack write access to most of the hierarchy.
The exceptions for normal users are /tmp, /var/tmp, /dev/shm, as well as the home directory $HOME (usually found below /home) and the runtime directory $XDG_RUNTIME_DIR (found below /run/user) of the user, which are all writable.
For unprivileged system processes, only /tmp, /var/tmp and /dev/shm are writable. If an unprivileged system process needs a private writable directory in /var or /run, it is recommended to either create it before dropping privileges in the daemon code, to create it via tmpfiles.d(5) fragments during boot, or via the StateDirectory= and RuntimeDirectory= directives of service units (see systemd.unit(5) for details).
Unix file systems support different types of file nodes, including regular files, directories, symlinks, character and block device nodes, sockets and FIFOs.
It is strongly recommended that /dev is the only location below which device nodes shall be placed. Similarly, /run shall be the only location to place sockets and FIFOs. Regular files, directories and symlinks may be used in all directories.
Developers of system packages should follow strict rules when placing their own files in the file system. The following table lists recommended locations for specific types of files supplied by the vendor.
Table 1. System Package Vendor Files Locations
Additional static vendor files may be installed in the /usr/share hierarchy to the locations defined by the various relevant specifications.
During runtime, and for local configuration and state, additional directories are defined:
Table 2. System Package Variable Files Locations
Programs running in user context should follow strict rules when placing their own files in the user's home directory. The following table lists recommended locations in the home directory for specific types of files supplied by the vendor if the application is installed in the home directory. (Note, however, that user applications installed system-wide should follow the rules outlined above regarding placing vendor files.)
Table 3. User Package Vendor File Locations
Additional static vendor files may be installed in the ~/.local/share hierarchy to the locations defined by the various relevant specifications.
During runtime, and for local configuration and state, additional directories are defined:
Table 4. User Package Variable File Locations
systemd(1), hier(7), systemd-path(1), systemd-gpt-auto-generator(8), sysctl.d(5), tmpfiles.d(5), pkg-config(1), systemd.unit(5)
File System Hierarchy
IEEE Std 1003.1
XDG Base Directory Specification
Multiarch Architecture Specifiers (Tuples)