4.2. Subdirectories for components of installed software

All of these directories are, by default, subdirectories of the installation prefixes described in the previous section. However, the variables may be reset to locations outside the installation prefixes, and all profiles of this specification do this for some of the variables.

4.2.1. bindir: User commands

Most executable files should be installed in this directory. (See Section 4.2.2, “sbindir: System management commands” and Section 4.2.3, “libexecdir: Programs not meant to be run directly by a human” for the exceptions.)

Mutable and machine-specific files may not be installed in this directory, even if they are executable. Subdirectories may not be created within bindir.

Files that are not executable may not be installed in this directory, even if they are in some sense “programs.” All files installed in bindir must be recognizable by the system call execve as executable, assuming the CPU and operating system support execution of that type of program. Software compliant with this specification must not ever rely on the fallback behavior of the C library functions execlp and execvp when execve fails with code ENOEXEC.

The default value of bindir is $(exec_prefix)/bin.

Rationale

Shells do not search PATH for any command whose name contains slashes, so it doesn’t work to try to use subdirectories of bindir as namespaces for commands.

The fallback behavior of execlp and execvp is to attempt to execute the offending file as if it were a /bin/sh script. This has unpredictable consequences when the file isn’t a /bin/sh script. It is also inconsistent with the behavior of all the other exec* functions, and with the behavior of programming languages that implement PATH search themselves rather than relying on the C library to do it. Finally, it is fully obsoleted by the #! mechanism.

4.2.2. sbindir: System management commands

Executable files that are exclusively useful to the system administrator (e.g. fsck), and executables that implement system services (e.g. sshd), should be installed in this directory. The word “exclusively” in the previous sentence is intentional. If there is any plausible situation where an unprivileged user might want to use a program, it should be placed in bindir, not sbindir.

All the requirements on files installed in bindir also apply to files installed in sbindir.

Subdirectories may not be created within sbindir, for the same reason this is forbidden for bindir.

The default value of sbindir is $(exec_prefix)/sbin.

A profile may set sbindir equal to bindir. Therefore, software packages may not install files with the same base name in both directories.

Interpretive note

The division between bindir and sbindir was not created for security reasons, or to prevent inquisitive users from seeing the operating system. Rather, the goal was to remove programs that are not useful to unprivileged users from the default PATH, thus reducing clutter in shell command completion and whatnot. Therefore, sbindir should still be accessible to unprivileged users and the programs within should still be readable and executable by unprivileged users.

4.2.3. libexecdir: Programs not meant to be run directly by a human

Executable files that are primarily or exclusively meant to be run by other programs, rather than directly by humans, should be installed in this directory.

Executables that implement system services are an exception; despite usually being run by another program (the system service orchestrator), they should be installed in sbindir.

All the requirements on files installed in bindir also apply to files installed in libexecdir.

Unlike bindir, software packages may create subdirectories of libexecdir and place executables within these subdirectories.

The default value of libexecdir is $(exec_prefix)/libexec.

A profile may set libexecdir equal to libdir. Therefore, software packages may not install files with the same relative pathname in both directories.

Rationale

It is useful for the system administrator to be able to run programs that implement system services as ordinary shell commands, for troubleshooting and testing.

Programs that are run by other programs are usually invoked by their full pathname, rather than relying on PATH search, so subdirectories of libexecdir work as expected, and can be useful in avoiding filename collisions.

4.2.4. sysconfdir: Machine-specific, system-wide configuration files

System-wide configuration files—that is, editable files, meant to modified by the system administrator, to adjust the default behavior of one or more programs for an entire machine—should be installed in this directory. Programs that need to install more than one or two configuration files in sysconfdir should create an appropriately named subdirectory and place all their configuration files inside.

Files that can be modified by individual users on a multi-user system, to adjust program behavior just for the user who modified them, may not be installed in this directory; they belong in users’ home directories. See Section 8.5, “User home directories”.

Files that define the default behavior of a program, but are not intended to be modified, may not be installed in this directory; they belong in datadir.

Installation processes must take care, when installing or updating files within sysconfdir, not to overwrite any local modifications to existing files.

To be revised

Add discussion of systemd-style drop-in directories and override files.

Executable files may only be installed in sysconfdir if they are also “system-wide configuration files” as defined at the beginning of this section. (The shell scripts used by System V init to control startup and shutdown are a good example of executables that are also system-wide configuration files.) Machine-code executables may not be used as configuration files, because they are not editable.

To be revised

I don’t love using a code-forge repo as a reference, even for an example; anyone know of a historical retrospective on init(8), or like that?

Mutable files may not be installed in this directory; they belong in localstatedir.

Interpretive note

Programs are allowed to modify files in sysconfdir, as long as they only do this during system maintenance operations or as a consequence of an explicit human action. For example, the system package manager will regularly need to alter files within sysconfdir when packages are updated; this is a system maintenance operation, so it is compliant with this specification. For another example, the passwd command’s entire purpose is to update $(sysconfdir)/shadow, but it only does this when a human wants to change a password, so it is compliant, and its existence does not mean $(sysconfdir)/shadow should be considered mutable.

The default value of sysconfdir is $(prefix)/etc.

No files are required to exist within sysconfdir. There are many files that almost always will exist, but nonetheless they should not be assumed to exist.

When the C library provides an API for looking up data that is usually stored in a well-known file within sysconfdir, there is no requirement for the data to actually be sourced from that file. In many cases, the data won’t be exclusively sourced from that file even when it does exist. Programs should therefore prefer the library APIs whenever possible.

To be revised

Should we still be requiring the locations below for SGML and XML catalog files? Abstractly it seems like they belong in localstatedir instead. I don’t know how they are currently handled in practice.

4.2.4.1. $(sysconfdir)/X11: Configuration directory for the X Window System

If the X Window System is installed, its configuration files must be placed in this subdirectory of sysconfdir, not in their historical location within libdir.

4.2.4.2. $(sysconfdir)/sgml: Centralized catalogs for SGML

Centralized catalog files for all SGML DTDs installed on the system shall be installed in this directory.

A “super” catalog file, referencing all of the centralized catalogs, shall be maintained at $(sysconfdir)/sgml/catalog.

Configuration files relevant to multiple SGML processors may also be installed in this directory.

4.2.4.3. $(sysconfdir)/xml: Centralized catalogs for XML

Centralized catalog files for all XML namespaces with schemas installed on the system shall be installed in this directory.

A “super” catalog file, referencing all of the centralized catalogs, shall be maintained at $(sysconfdir)/xml/catalog.

Configuration files relevant to multiple XML processors may also be installed in this directory.

4.2.5. includedir: C-family header files

“Header files” (files to be used as the direct object of the #include preprocessing directive) for any programming language in the C family should be placed in this directory.

C header files installed in this directory must be usable with an ISO C-compliant compiler, and should also be usable with a C++ compiler.

Executable, mutable, and machine-specific files may not be installed in this directory.

The default value of includedir is $(prefix)/include.

Rationale

The C family gets an installation directory exclusively for its header files because of C’s historical importance as the principal system programming language for Unix systems. It is not within datarootdir both because of historical practice, and because C-family header files are frequently architecture-dependent.

4.2.6. libdir: Software libraries and miscellaneous architecture-dependent data

Machine-code libraries, whether statically or dynamically linked, should be installed in this directory.

Other architecture-dependent static shareable data files may also be installed in this directory, when there is no more specific installation directory for them. Such files should be installed into a subdirectory that identifies their purpose and/or format, unless there is a compelling reason why they need to be directly in libdir.

Miscellaneous architecture-independent static data files should instead be installed in datadir. However, it can be difficult to tell whether a file is truly architecture-independent; when in doubt, assume it isn’t.

Executable files may only be installed in libdir if they are also machine-code libraries and they do not need to be accessible as shell commands. (For example, GNU libc’s libc.so.6 is a machine-code library. It can be used as an executable, but this is a secondary function that doesn’t require it to be visible in PATH.)

Mutable and machine-specific files may not be installed in this directory.

The default value of libdir is $(exec_prefix)/lib.

4.2.6.1. $(libdir)/modules: Loadable kernel modules and related files

This directory is reserved for installation of modular components of the OS kernel that do not need to be available to the bootloader, and files holding related information (e.g. a catalog of available modules). All files within this directory should be placed in subdirectories whose names identify the exact kernel that the modules are to be used with.

4.2.7. datadir: Miscellaneous architecture-independent data

Architecture-independent static shareable data files should be installed in this directory, if there is no more specific installation directory for them. All such files should be installed into subdirectories that identify their purpose, format, and/or the application that created them.

Software packages may not install files directly in datadir. Packages that need to install only a few files in datadir may use $(datadir)/misc instead of creating a directory in datadir.

Files which are architecture-dependent, executable, mutable, or machine-specific may not be installed in this directory. It can be difficult to be certain that files are architecture-independent; if there is any doubt, they should be placed in (a subdirectory of) libdir instead.

The default value of datadir is $(datarootdir).

4.2.7.1. $(datadir)/misc: Miscellaneous miscellaneous architecture-independent data

This directory offers an alternative to creating an application-specific subdirectory of datarootdir. It should only be used by applications that install only a few architecture-independent, shareable data files. Applications that install files in this directory must take care to use names that will not collide with any other application.

Examples

Here are a few examples of files that are suitable for installation in this directory. Many of these files were, in the past, installed directly in datadir or libdir.

FileDescription
airportList of IATA three-letter identifying codes for major airports
asciiASCII character set table
birthtokenTraditional stone and flower for each month
gprof.callgData used by gprof when processing call-graph profiles
gprof.flatData used by gprof when processing flat profiles
inter.phoneCountry codes for international telephone calls
magicRules for identifying file formats, used by the file command (textual)
magic.mgcRules for identifying file formats, used by the file command (compiled)
man.templateTemplate for writing manpages in ‘man’ format
mdoc.templateTemplate for writing manpages in ‘mdoc’ format
na.phoneNorth American (NANPA) area codes for telephone numbers
operatorPrecedence table for operators in the C language
termcapTerminal capability database (textual)
termcap.dbTerminal capability database (compiled)
units.libDatabase of units of measurement, used by the units command

4.2.8. $(datarootdir)/color: Color management information

Packaged color management files that are potentially useful to more than one application should be installed in this directory.

All the requirements on files installed in datadir also apply to files installed in $(datarootdir)/color.

The top-level directory $(datarootdir)/color may not contain any files; all files should be in subdirectories which identify the files’ purpose and/or format. At present, we specify only one such subdirectory: $(datarootdir)/color/icc stores color profiles in the ICC (International Color Consortium) v4 format [icc-specs].

4.2.9. $(datarootdir)/dict: Word lists for spelling checkers

Comprehensive lists of words in natural languages, for use by spelling checkers, should be installed in this directory.

All the requirements on files installed in datadir also apply to files installed in $(datarootdir)/dict.

Each list should be named using the English name for its language, in all lowercase ASCII letters, e.g. french or hokkien. When there is more than one spelling standard for a language, the common English identifier for the spelling standard should be prefixed to the language name, e.g. american-english and british-english. When there are several word lists available for a single language and standard, suffixes may be used to distinguish them, e.g. american-english-web2 and american-english-cracklib-small.

For compatibility with historical practice, if English word lists are installed, $(datarootdir)/dict/words should be a symbolic link to the word list for the system’s users’ preferred spelling standard for English. Spelling checkers should avoid using this link; instead, they should allow each user to select the word list they prefer, from all available.

All word lists installed in this directory should be plain text files with one word on each line, in the preferred collation order for the language. Word lists should be encoded in UTF-8 unless it is absolutely necessary to do otherwise (e.g. a word list for a language whose script hasn’t been added to Unicode).

Rationale

This directory only contains word lists because word lists are the only data files common to all spelling checkers.

4.2.10. $(datarootdir)/ppd: Printer descriptions

Packaged printer descriptions in PostScript Printer Description (PPD) format [ps-printer-desc], that are potentially useful to more than one application, should be installed in this directory or a subdirectory. The organization of files within $(datarootdir)/ppd is unspecified.

All the requirements on files installed in datadir also apply to files installed in $(datarootdir)/ppd.

4.2.11. $(datarootdir)/sgml: SGML DTDs and related files

Packaged files useful to more than one SGML processor, such as ordinary catalogs (not centralized catalogs, see $(sysconfdir)/sgml), DTDs, entity definitions, and style sheets, should be placed in this directory.

The top-level directory $(datarootdir)/sgml may not contain any files; all files should be in subdirectories which identify the DTD to which the files are relevant, or, if they are relevant to more than one DTD, otherwise unambiguously identify the group of files within.

All the requirements on files installed in datadir also apply to files installed in $(datarootdir)/sgml.

4.2.12. $(datarootdir)/xml: XML schemas and related files

Packaged files useful to more than one XML processor, such as schema definitions and style sheets, should be placed in this directory. Centralized catalogs are not to be installed in this directory; they belong in $(sysconfdir)/xml.

The top-level directory $(datarootdir)/xml may not contain any files; all files should be in subdirectories which identify the XML namespace to which the files are relevant, or, if they are relevant to more than one namespace, otherwise unambiguously identify the group of files within.

All the requirements on files installed in datadir also apply to files installed in $(datarootdir)/xml.

4.2.13. localedir: Localization data, such as message catalogs

Files which help adapt a program to a particular community of humans (a locale) should be installed in subdirectories of this directory. For example, “catalogs” of messages emitted by a program, in several human languages, belong here.

All the requirements on files installed in datadir also apply to files installed in localedir.

The default value of localedir is $(datarootdir)/locale.

Localization data is stored in a structured hierarchy of subdirectories of localedir: <locale>/<category>/<files>.

To be revised

This used to say that locale identification strings were taken from POSIX, but the current version of POSIX leaves the rules for locale names much vaguer than we want. Some of this text may belong in Section 2.1.2, “Locales”.

The <locale> component identifies the community of humans. This component must be a locale identification string. Locale identification strings have the form <language>[_<territory>][.<encoding>][@<modifier>].

The <language> field identifies the language or language family spoken in the community, using one of the two- or three-letter language codes defined by ISO 639, written with lowercase ASCII letters. Two-letter codes must be used for all languages that have one.

The <territory> field, when present, identifies the geographic territory of the community and/or the geographic variant of the language family, using one of the two-letter country codes defined by ISO 3166, written with uppercase ASCII letters. For example, this is useful to distinguish peninsular Portuguese (pt_PT) from Brazilian Portuguese (pt_BR).

To be revised

I cut a bunch of text about “numbers of international standards” that was either outdated or just plain wrong. This should be revised to reflect how setlocale(3) and man(1) actually behave.

The <encoding> field, when present, identifies the character encoding preferred in the community. It should be in all lowercase ASCII letters and digits with minimal punctuation, e.g. “utf8”, not “UTF-8.”

To be revised

Can we say that when the <encoding> is omitted the default is UTF-8, or is it still too soon for that?

The <modifier> field, when present, further categorizes the locale. It can be used to distinguish language variants that are inadequately handled by the <territory> component, or to allow for conflicting cultural requirements, such as competing definitions of collating order. It should be in all lowercase ASCII letters and digits with minimal punctuation.

The <category> component indicates what aspect of the locale is governed by the files within. The categories and their functions are:

CategoryGoverns
LC_ADDRESSFormatting of addresses and geography-related items
LC_COLLATEString collation
LC_CTYPECharacter classification
LC_IDENTIFICATIONMetadata describing the locale
LC_MEASUREMENTSettings related to measurements (e.g. metric versus US customary)
LC_MESSAGESLocalizable natural-language messages
LC_MONETARYFormatting of monetary values
LC_NAMEFormatting of salutations for persons
LC_NUMERICFormatting of nonmonetary numeric values
LC_PAPERSettings related to the standard paper size
LC_TELEPHONEFormats to be used with telephone services
LC_TIMEFormatting of date and time values

To be written

Explain the <category> directories in more detail and describe what files are to be installed in each.

4.2.14. mandir: Unix “man page” manuals

Documentation in the format expected by the man command should be installed in subdirectories of this directory.

The default value of mandir is $(datarootdir)/man.

All the requirements on files installed in datadir also apply to files installed in mandir.

Manual pages are stored in a structured hierarchy of subdirectories of mandir: [<locale>/]man<section>[/<arch>]. The <locale> and <arch> components of this hierarchy are optional, as described below.

Individual manual pages should be stored with file names that end with a numeric suffix, matching their section number; for example, the manual page for the ls command should be installed to man1/ls.1, possibly within a <locale> directory.

Manual pages may be installed compressed, in which case the numeric suffix should be followed by the usual suffix identifying the compression format, e.g. man1/ls.1.gz for gzip-format compression.

As a precaution against name collisions, some large sets of package-specific manual pages have an additional alphabetical suffix inserted right after the section number. For example, the C function strvis might be provided by both the system C library and the third-party libbsd library. The C library’s version of the manpage should be installed as man3/strvis.3 and libbsd’s as man3/strvis.3bsd.

The <section> component of the manual page directory hierarchy classifies each manual page into one of eight topic-based “sections:”

SectionDocumentsDetails
1User commandsPrograms that are generally useful to all users of the system.
2System callsC library functions that are implemented as direct calls to OS kernel services.
3Library functionsC library functions that are not just direct calls to OS kernel services. (They may still make use of system calls as part of what they do.) Documentation of library functions for other programming languages may also be placed in this section, but each such manpage must have an alphabetical name suffix (see above).
4DevicesThe interfaces to peripheral hardware provided by the device files found in /dev, and the kernel interfaces to networking protocol support.
5File formatsCommon file formats. Notably, documentation for system configuration files (Section 4.2.4, “sysconfdir: Machine-specific, system-wide configuration files”) should be in this section.
6GamesPrograms that implement games.
7MiscellaneousAll manpages that do not fit in any other section can be placed here.
8System management commandsPrograms that are exclusively useful to the system administrator, and programs that implement system services. The relationship between section 8 and section 1 is an exact parallel of the relationship between sbindir and bindir.

To be revised

The above does not appear to be an accurate description of the contents of man4 on my computer. Notably, all the networking address families are in man7.

Optionally, preformatted manual pages may be installed in a parallel set of directories at the section level: cat<section> holds the preformatted versions of the pages in man<section>. Preformatted manual pages may not be installed without the corresponding source-format manual pages. Cached copies of locally-formatted manual pages are not to be written back to the directories for preformatted manual pages; they must be written to $(localstatedir)/cache/man instead.

The <locale> component of the manual page directory hierarchy supports simultaneous installation of manual pages written in multiple languages. If this component is present, it must be a locale identification string that uniquely identifies the language for the manpages within that directory.

Systems which offer manual pages in only one language may omit the <locale> component and store the <section> directories directly in mandir. Systems which offer manual pages in more than one language should place all their manual pages in <locale> subdirectories.

The <arch> component of the manual page directory hierarchy supports simultaneous installation of several architecture-specific variants of man pages, for device drivers and other software that is tightly coupled to the computer’s hardware. It should only be used when necessary.

To be revised

I cut the <arch> example because the ctrlaltdel(8) command is not a good example: what it does is at least theoretically applicable to any computer with a keyboard that has Ctrl, Alt, and Del keys, and in any case there would be no reason to have multiple versions of this command that do different things depending on the CPU architecture! Let’s find an example of something where one would actually want manX/i386/foobie.X and manX/aarch64/foobie.X to coexist and say different things, please.

4.2.15. infodir: GNU Info-format manuals

Documentation in the format expected by the info command should be installed in this directory.

All the requirements on files installed in datadir also apply to files installed in infodir.

To be revised

Should we mention install-info(8) and/or the dir file here?

The default value of infodir is $(datarootdir)/info.

4.2.16. docdir: Other documentation

Documentation in any format besides those used by man and info, such as HTML, PDF, and plain text, should be installed in subdirectories of this directory.

All the requirements on files installed in datadir also apply to files installed in docdir.

No files may be installed directly into docdir, only into a subdirectory named after the software package whose documentation it is.

The default value of docdir is $(datarootdir)/doc.

4.2.17. localstatedir: Persistent mutable data

All persistent mutable files that are part of an installable software package should be installed to one of the subdirectories of localstatedir, defined in subsections of this section. Files may not be installed directly in localstatedir.

New subdirectories of localstatedir may be added in future revisions of this specification. All such directories will have system-wide functions, as the existing subdirectories do. Software packages may not unilaterally add new directories to the top level of localstatedir.

Programs that use persistent mutable files need to take precautions against unexpected modifications by other processes on the same system; see Section 2.2.4, “Handling of mutable files” for further discussion.

The default value of localstatedir is $(prefix)/var.

4.2.17.1. $(localstatedir)/cache: System-wide data caches

System services that do time-consuming work whose result can usefully be cached and reused, such as computation or network downloads, should create a subdirectory of $(localstatedir)/cache and store cache files within.

Files stored in subdirectories of $(localstatedir)/cache may be expired in a service-specific manner, by the system administrator, or both. The service must always be able to recover from unexpected deletion of these files. The service-specific directories will normally not be deleted, but services should gracefully recreate them if necessary, as well.

Files stored in subdirectories of $(localstatedir)/cache must remain valid across service restarts and system reboots.

A few commonly used subdirectories of $(localstatedir)/cache are described below. This specification makes no further requirements of the contents of service-specific subdirectories that are not described below.

Rationale

The existence of a separate directory for cached data allows system administrators to set different disk and backup policies from other directories in /var.

4.2.17.1.1. $(localstatedir)/cache/fonts: Locally-generated fonts

The directory $(localstatedir)/cache/fonts should be used to store any dynamically-created font files. These files should be organized into appropriately-named subdirectories rather than being placed directly in this directory.

Future directions

Future revisions of this specification may make more specific requirements for the organization of $(localstatedir)/cache/fonts. Other existing standards and software that describe directory hierarchies containing fonts include the TeX Directory Structure [tex-directory-structure] and fontconfig [fontconfig].

4.2.17.1.2. $(localstatedir)/cache/man: Locally-formatted man pages

Cached copies of locally-formatted man pages should be stored in appropriately named subdirectories of this directory.

The directory structure below $(localstatedir)/cache/man mimics the directory structure below $(mandir), with an adjustment to allow for the possibility of multiple man page hierarchies.

Cached locally-formatted copies of the unformatted man pages stored in $(mandir)[/<locale>]/man<section> shall be stored in $(localstatedir)/cache/man/<catpath>[/<locale>]/cat<section>. <catpath> is derived from the $(prefix) component of $(mandir) by removing a leading usr component, if present.

Examples

Unformatted man pageLocation for formatted page
/usr/share/man/man1/ls.1$(localstatedir)/cache/man/cat1/ls.1
/usr/local/share/man/pt_BR/man3/curl_easy_init.3$(localstatedir)/cache/man/local/pt_BR/cat3/curl_easy_init.3

Preformatted manpages that are included with a software package shall be installed in mandir, not in this directory.

Historical note

Release 1.2 of this specification used $(localstatedir)/catman for this hierarchy. The path has been moved under $(localstatedir)/cache to better reflect the dynamic nature of the formatted man pages. The directory name has been changed to man to allow for enhancing the hierarchy to include post-processed formats other than “cat,” such as PostScript, HTML, or DVI.

For backward compatibility with old versions of the man command, releases prior to 4.0 permitted locally formatted manpages to be written to mandir; this is no longer allowed, as it conflicts with the general policy that mutable files may not be stored in mandir’s parent, datarootdir.

4.2.17.2. $(localstatedir)/lib: Mutable application and system state

This hierarchy holds persistent mutable state information pertaining to an application or the system.

It should never be necessary to modify files in $(localstatedir)/lib to configure the system. All system-wide configuration files should be placed in sysconfdir.

Additionally, the specific file hierarchy used to store data within $(localstatedir)/lib should not be exposed or relevant to regular users. Data whose filesystem structure is necessarily relevant to regular users (such as the contents of a web site served by the system) should be stored in /srv instead.

Data should only be stored in $(localstatedir)/lib if there is no more specific place to put it. In particular, cached data (files that can safely be deleted at any time to recover disk space) belongs in $(localstatedir)/cache; spooled data (user-generated data awaiting automated processing) belongs in $(localstatedir)/spool; and system logs belong in $(localstatedir)/log.

Files shall not be placed directly in $(localstatedir)/lib. Each application (or group of inter-related applications) must create and use a subdirectory of $(localstatedir)/lib for its data, taking care to choose a name that will not collide with any other application. Alternatively, applications that need to maintain only one or two persistent mutable state files may place them in $(localstatedir)/lib/misc.

Historical note

Older versions of this specification did not require applications to use a subdirectory.

To be revised

How old, exactly? Do we still need this note?

/var/lib/<name> is the location that must be used for all distribution packaging support. Different distributions may use different names, of course.

To be revised

I don’t understand the preceding paragraph. It sounds like it’s picking a fight with some unspecified distribution from days of yore. Do we still need it? Can we clarify it?

4.2.17.2.1. $(localstatedir)/lib/misc: Miscellaneous state files

This directory offers an alternative to creating an application-specific subdirectory of $(localstatedir)/lib. It should only be used by applications that need to maintain only one or two persistent mutable state files. Applications that install files in this directory must take care to use names that will not collide with any other application.

As an exception to the normal rule that empty installation directories need not exist, $(localstatedir)/lib/misc should be created at initial system installation time, and preserved, even when it is empty. However, like all other installation directories, applications must be prepared to cope with it not existing.

This specification recommends that the files stored in $(localstatedir)/db in current BSD releases should be moved to this directory. These include locate.database and mountdtab, and the kernel symbol database(s).

To be revised

Do we want to keep making this recommendation? Have we actually had a conversation with the BSD people, or any other relevant stakeholders, about /var/db vs /var/lib(/misc)?

4.2.17.2.2. $(localstatedir)/lib/<editor>: Editor backup files and state (deprecated)

Editing tools that write state files during normal operation, may use a subdirectory of $(localstatedir)/lib for this purpose, named after the editor. For example, the text editor elvis might use $(localstatedir)/lib/elvis.

Use of $(localstatedir)/lib/<editor> is deprecated. Editors should instead place state files that are associated with a file being edited, in the same directory as that file, whenever possible. When this is not possible (e.g. when the user running the editor can modify a specific file in a directory, but cannot create new files there), they should be placed in a suitable location within the home directory of the user running the editor, as should state files not associated with any particular file being edited. This is the behavior of current versions of emacs and vim.

Rationale

Examples of state files used by editors include: automatically saved copies of modifications to files that have not yet been explicitly saved, “lock” files that indicate a file is currently being edited, and data used to recover from a crash of the editor itself.

Historically, the vi editor used $(localstatedir)/preserve to store crash-recovery files. However, each editor uses its own format for its state files, so a separate directory is needed for each editor.

$(localstatedir)/lib/<editor> has to be writable by all users on a multi-user system, which is troublesome for security. Placing temporary state files alongside the file being edited, or else within the home directory of the user running the editor, avoids the security issues. See Section 2.2.4.1, “Security considerations for mutable files and world-writable directories” for further discussion.

4.2.17.2.3. $(localstatedir)/lib/color: Locally created color management information

This directory is the home for ICC color management files installed dynamically (not as part of any software package). The contents of this directory shall follow the same rules as the contents of the $(datarootdir)/color directory.

4.2.17.2.4. $(localstatedir)/lib/hwclock: State directory for hwclock

This directory contains the file $(localstatedir)/lib/hwclock/adjtime, which is created and updated by the hwclock command. If the hwclock command is not used to maintain an accurate real-time clock on the system, then this directory should not exist.

Rationale

The “real-time clock” is a battery-powered hardware clock that tracks calendar time and keeps running when the rest of the system is powered down. “Real time” in this context refers to calendar time, and has nothing to do with real-time task scheduling.

The real-time clock is often imprecise, compared to the timekeeping done by the operating system while the computer is running; one of the functions of hwclock is to monitor and compensate for its errors, using data stored in this file.

In FHS 2.1, this file was stored in sysconfdir, but as it is a mutable file, that location was inappropriate.

4.2.17.3. $(localstatedir)/log: Log files and directories

Applications that generate their own log files in the course of normal operation should create a suitably named subdirectory of $(localstatedir)/log at installation time, and write their log files to that directory. This specification makes no requirements on the format or contents of application log files.

Applications that send their log records to the global system log (syslog or equivalent) should not create any files or directories in $(localstatedir)/log.

The following special-purpose files may exist at the top level of $(localstatedir)/log. If they exist, they shall have the indicated contents, and applications that generate relevant log records should update them. However, applications must not create them if they don’t already exist.

FileDescription
lastlogrecord of last login of each user
btmprecord of failed logins
wtmprecord of all logins and logouts

To be revised

Move all discussion of lastlog/btmp/wtmp/utmp/utmpx/wtmpx to its own section, document formats, mark as deprecated due to intractable Y2038 issues.

Otherwise, the top level of $(localstatedir)/log is reserved for use by the global system log. The software responsible for maintaining this log (syslogd, historically) may create files and directories at the top level with any names besides the ones listed above, taking care not to collide with application-specific subdirectories, and use them as it sees fit.

To be revised

Should we say something about log rotation here?

4.2.17.4. $(localstatedir)/spool: Application spool data

Applications which receive user-supplied data, store it, and process it in the background, perhaps after some delay, should create a suitably named subdirectory of $(localstatedir)/spool at installation time, and store the user-supplied data there.

Each application that stores user-supplied data in $(localstatedir)/spool is responsible for all management of files in its subdirectory. For example, often it will be appropriate to delete files that have been completely processed.

Common types of user-supplied data include:

  • Documents waiting to be printed out
  • Outgoing mail and news that has not yet been accepted by its destination
  • Incoming mail and news that has not yet been delivered to local users
  • Tasks scheduled to be executed at some point in the future

This specification does not require any particular subdirectories to exist within $(localstatedir)/spool. However, certain groups of files that historically were stored in $(localstatedir)/spool should now be placed elsewhere, and vice versa:

4.2.17.5. Special-purpose subdirectories of localstatedir

These directories are not installation directories; software will generally not need to create files in them during its installation process. However, software that uses these directories, or the data stored within, should look for them relative to localstatedir.

All of these directories are optional; they should exist only if the relevant subsystem is in use.

DirectoryDescription
$(localstatedir)/accountThis directory holds the current active process accounting log and the composite process usage data (as used in some UNIX-like systems by lastcomm and sa)
$(localstatedir)/crashThis directory holds system crash dumps, if the system is configured to produce them.
$(localstatedir)/mail If the system delivers email to local users by writing them to files in the standard Unix mbox format [rfc4155], those files may be placed in this directory. Each file within this directory should have the same name as the account name of the local user whose mail it holds.
$(localstatedir)/nisVariable data used by the Sun NIS+ system for network-wide user accounts should be placed in this directory.
$(localstatedir)/ypVariable data used by the Sun NIS system (also known as Sun Yellow Pages) for network-wide user accounts should be placed in this directory.

As of FHS 4.0, use of $(localstatedir)/mail for local mail delivery is discouraged. Locally delivered mail should instead be written to an appropriate location within each local user’s home directory. Use of mbox-format files is also discouraged. The format is underspecified, with several incompatible variations seeing wide use, and it cannot efficiently handle large volumes of mail.

4.2.17.6. Reserved subdirectories of localstatedir

Several more subdirectories of localstatedir were historically common, but should not be used by new applications. They are:

  • $(localstatedir)/backups
  • $(localstatedir)/cron
  • $(localstatedir)/db
  • $(localstatedir)/msgs
  • $(localstatedir)/preserve

These directories are not required to exist.

Future directions

Future revisions of this specification might either remove these directories altogether, or flesh out their expected contents and sanction their continued use.

4.2.18. runstatedir: Transient mutable data

Programs should store all their transient mutable files in this directory or in one of its subdirectories. Programs that need to create only one or two transient files may place them directly in runstatedir; programs that need several transient files should create a subdirectory and place all their files within.

Software packages should never install anything in this directory, because all files in this directory, and all subdirectories not listed below, are completely erased every time the system is booted. The variable exists to tell programs where to find this directory at runtime.

For the same reason, programs that use this directory must be prepared to recreate everything they put here, from scratch, every time they start up. However, they must not assume the files they mean to create don’t exist, either; garbage files might be left over from a previous run of the same program. See Section 2.2.4, “Handling of mutable files” for further discussion.

Because runstatedir’s contents are erased on every boot, it is an exception to the normal rule that empty directories need not exist. For security reasons, the top level of runstatedir is writable only by root. System services that run as unprivileged users may therefore need to arrange for files and directories that they need in runstatedir to be created in advance during service startup.

The default value of runstatedir is $(prefix)/run.

Daemon processes that create “process identifier” (PID) files should place them directly within runstatedir and should name them <program-name>.pid, where <program-name> is the name of the daemon’s primary executable (the one installed in sbindir). For example, the crond daemon’s PID file should be named /run/crond.pid. Each PID file should contain the daemon’s numeric PID as ASCII decimal digits, with no padding on the left, followed by a newline character. For example, if crond was running as process 25, /run/crond.pid should contain three characters: 25␊.

Programs that create local sockets in order to provide system-wide services should place them within runstatedir, but the exact pathname of each is unspecified.

The following special-purpose files may exist at the top level of runstatedir. If they exist, they shall have the indicated contents, and applications that generate relevant records should update them. However, applications must not create them if they don’t already exist.

FileDescription
utmpInformation about users currently logged in

To be revised

Move all discussion of lastlog/btmp/wtmp/utmp/utmpx/wtmpx to its own section, document formats, mark as deprecated due to intractable Y2038 issues.

Historical note

PID files were historically placed in /etc, and local sockets were historically placed in /tmp, /dev, or localstatedir. PID files have been moved to runstatedir because /etc is supposed to be as read-only as possible in normal operation. Sockets formerly in /tmp have been moved to runstatedir for security; sockets formerly in /dev and localstatedir have also been moved, for consistency and to reduce risk of name collisions.

4.2.18.1. $(runstatedir)/lock: Lock files

$(runstatedir)/lock is the designated location for lock files. Lock files are transient files whose existence indicates that a system-wide resource is currently in use exclusively by one particular process. The name of each lock file must unambiguously identify the resource that it mediates access to. To work correctly, lock files must be created with an unusual sequence of file operations; see Section 2.2.4.2, “Creation of lockfiles”.

Nothing may be placed in $(runstatedir)/lock besides lock files and directories that group lock files into categories.

Because runstatedir’s contents are erased on every boot, $(runstatedir)/lock is an exception to the normal rule that empty directories need not exist. The boot step that erases the contents of runstatedir must recreate $(runstatedir)/lock immediately afterward.

Unless there is a specific reason to do otherwise, all lock files should be ordinary text files, containing the process ID (PID) of the process holding the lock, as an ASCII decimal number, with a trailing newline. The process ID may be padded on the left with ASCII space characters.

4.2.18.1.1. Lock files for hardware devices

All lock files for hardware devices must be placed directly in $(runstatedir)/lock. The lock file for a specific device must be named LCK..<device>, where <device> is the base name of the device file. For example, to lock /dev/ttyS0, create the file $(runstatedir)/lock/LCK..ttyS0.

To ensure full compatibility with other programs that use device lock files, the process ID within a device lock file must be padded on the left with ASCII spaces to ten bytes wide. For example, if process 1230 has locked /dev/ttyS0, then $(runstatedir)/lock/LCK..ttyS0 must contain these eleven bytes: ␠␠␠␠␠␠1230␊, where is ASCII space and is ASCII newline.