# Unix filesystem

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Unix_filesystem
> Markdown URL: https://mediated.wiki/source/Unix_filesystem.md
> Source: https://en.wikipedia.org/wiki/Unix_filesystem
> Source revision: 1353355403
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Directory structure used by a Unix-like operating system}}
{{Redirect|Unix file system|UFS, a specific file system used by many Unix and Unix-like operating systems|Unix File System}}
[[File:Version 7 UNIX SIMH PDP11 Filesystem Layout.png|thumb|[Version 7 Unix](/source/Version_7_Unix) filesystem layout: subdirectories of "/" and "/usr"]]
[[File:Standard-unix-filesystem-hierarchy.svg|thumb|An overview of a [Unix](/source/Unix) filesystem layout]]

In [Unix](/source/Unix) and [operating system](/source/operating_system)s inspired by it, the [file system](/source/file_system) is considered a central component of the operating system.<ref name="Ritchie">{{cite journal |last1= Ritchie |first1= D.M. |author-link1= Dennis Ritchie |last2= Thompson |first2= K. |author-link2= Ken Thompson  |title= The UNIX Time-Sharing System |journal= Bell System Tech. J. |volume= 57 |issue= 6 |pages= 1905–1929 |date= July 1978 |doi=10.1002/j.1538-7305.1978.tb02136.x|citeseerx= 10.1.1.112.595 }}</ref> It was also one of the first parts of the system to be designed and implemented by [Ken Thompson](/source/Ken_Thompson) in the first experimental version of Unix, [dated 1969](/source/History_of_Unix).<ref name="evolution"/>

As in other operating systems, the filesystem provides information storage and retrieval, and one of several forms of [interprocess communication](/source/interprocess_communication), in that the many small programs that traditionally form a Unix system can store information in files so that other programs can read them, although [pipes](/source/Pipeline_(Unix)) complemented it in this role starting with the [Third Edition](/source/Research_Unix). Also, the filesystem provides access to other resources through so-called ''[device file](/source/device_file)s'' that are entry points to [terminals](/source/computer_terminal), [printers](/source/computer_printer), and [mice](/source/computer_mouse).

The rest of this article uses ''Unix'' as a [generic name](/source/Generic_trademark) to refer to both the original Unix operating system and its many [workalikes](/source/Unix-like).

==Principles==
The filesystem appears as one [rooted tree](/source/rooted_tree) of directories.<ref name="Ritchie"/> Instead of addressing separate volumes such as [disk partitions](/source/disk_partitions), removable media, and [network share](/source/network_share)s as separate trees, such volumes can be ''[mounted](/source/mount_(Unix))'' on a directory, causing the volume's file system tree to appear as that directory in the larger tree.<ref name="Ritchie"/> The root of the entire tree is denoted <code>/</code>.

In the original [Bell Labs Unix](/source/Research_Unix), a two-disk setup was customary, where the first disk contained startup programs, while the second contained users' files and programs. This second disk was mounted at the empty directory named <code>usr</code> on the first disk, causing the two disks to appear as one filesystem, with the second disk’s contents viewable at <code>/usr</code>.

Directories in Unix file systems do not ''contain'' files. Instead, they contain the names of files paired with references to so-called [inode](/source/inode)s, which in turn contain both the file and its [metadata](/source/metadata) (owner, permissions, time of last access, etc., but no name). Multiple names in the file system may refer to the same file, a feature termed a ''[hard link](/source/hard_link)''.<ref name="Ritchie"/> The mathematical traits of hard links make the file system a limited type of [directed acyclic graph](/source/directed_acyclic_graph), although the ''directories'' still form a tree, as they typically may not be hard-linked.<!--Mac OS X allows this, according to the article 'Hard link'.--> As originally envisioned in 1969, the Unix file system would in fact be used as a general graph with hard links to directories providing navigation, instead of path names.<ref name="evolution">{{cite conference |first=Dennis M. |last=Ritchie |year=1979 |title=The Evolution of the Unix Time-sharing System |conference=Language Design and Programming Methodology Conf. |url=http://cm.bell-labs.com/cm/cs/who/dmr/hist.html |access-date=2014-04-20 |archive-date=2015-04-08 |archive-url=https://web.archive.org/web/20150408054606/http://cm.bell-labs.com/cm/cs/who/dmr/hist.html |url-status=dead }}</ref>

===File types===
{{Main |Unix file types}}

The original Unix file system supported three types of files: ordinary files, [directories](/source/Directory_(computing)), and "special files", also termed device files.<ref name="Ritchie"/> The [Berkeley Software Distribution](/source/Berkeley_Software_Distribution) (BSD) and [System V](/source/System_V) each added a file type to be used for [interprocess communication](/source/interprocess_communication): BSD added [sockets](/source/Berkeley_sockets),<ref name="43bsd">{{cite book |last1= Leffler |first1= Samuel J. |author-link1= Samuel J Leffler |last2= McKusick |first2= Marshall Kirk |author-link2= Marshall Kirk McKusick |last3= Karels |first3= Michael J. |author-link3= Michael J. Karels |last4= Quarterman |first4= John S. |author-link4= John Quarterman |title= The Design and Implementation of the 4.3BSD UNIX Operating System |date= October 1989 |publisher= [Addison-Wesley](/source/Addison-Wesley) |isbn= 978-0-201-06196-3 |url-access= registration |url= https://archive.org/details/designimplementa0000unse }}</ref> while System V added [FIFO files](/source/Named_pipe).

BSD also added [symbolic link](/source/symbolic_link)s (often termed "symlinks") to the range of file types, which are files that refer to other files, and complement hard links.<ref name="43bsd"/> Symlinks were modeled after a similar feature in [Multics](/source/Multics),<ref name="FFS">{{cite web|last1=McKusick|display-authors=etal|first1=Marshall Kirk|title=A Fast Filesystem for Unix|url=https://docs.freebsd.org/44doc/smm/05.fastfs/paper.pdf|website=Freebsd.org|publisher=CSRG, UC Berkeley|access-date=16 November 2016}}</ref> and differ from hard links in that they may span filesystems and that their existence is independent of the target object. Other Unix systems may support additional types of files.<ref>{{man|2|stat|Linux}}</ref>

==Conventional directory layout==
{{Redirect|Usr||USR (disambiguation)}}
Certain conventions exist for locating some kinds of files, such as programs, system configuration files, and users' [home directories](/source/home_directories). These were first documented in the <code>hier(7)</code> [man page](/source/man_page) since [Version 7 Unix](/source/Version_7_Unix);<ref name="v7">{{man|7|hier|v7}}</ref> subsequent versions, derivatives and clones typically have a similar man page.<ref>{{man|7|hier|FreeBSD}}</ref><ref name="openbsd">{{man|7|hier|OpenBSD}}</ref><ref>{{cite web|title=hier(7) man page for 2.9.1 BSD|url=http://www.freebsd.org/cgi/man.cgi?query=hier&manpath=2.9.1+BSD}}</ref><ref>{{cite web|title=hier(7) man page for ULTRIX 4.2|url=http://www.freebsd.org/cgi/man.cgi?query=hier&manpath=ULTRIX+4.2}}</ref><ref>{{cite web|title=hier(7) man page for SunOS 4.1.3|url=http://www.freebsd.org/cgi/man.cgi?query=hier&manpath=SunOS+4.1.3}}</ref><ref>{{man|7|hier|Linux}}</ref>

The details of the directory layout have varied over time. Although the file system layout is not part of the [Single UNIX Specification](/source/Single_UNIX_Specification), several attempts exist to standardize (parts of) it, such as the [System V](/source/System_V) [Application Binary Interface](/source/Application_Binary_Interface), the [Intel Binary Compatibility Standard](/source/Intel_Binary_Compatibility_Standard), the Common Operating System Environment, and [FreeDesktop](/source/FreeDesktop)'s [Filesystem Hierarchy Standard](/source/Filesystem_Hierarchy_Standard) (FHS).<ref>{{cite web |title=Where to Install My Products on Linux? |url=http://www.linuxjournal.com/article/4121 |website=[Linux Journal](/source/Linux_Journal) |date=1 November 2000 |author=George Kraft IV |access-date=13 November 2014}}</ref>

Here is a generalized overview of common locations of files on a Unix operating system:
{|class="wikitable"
!Directory or file
!Description
|-
|<code>/</code>
|The slash <code>/</code> character alone denotes the root of the filesystem tree.
|-
|
<code>/bin</code>
|Stands for ''[binaries](/source/computer_program)'' and contains certain fundamental utilities, such as <code>ls</code> or <code>cp</code>, that are needed to mount <code>/usr</code>, when that is a separate filesystem, or to run in one-user (administrative) mode when <code>/usr</code> cannot be mounted. In System V.4, this is a [symlink](/source/symlink) to <code>/usr/bin</code>. Otherwise, it needs to be on the root filesystem itself.
|-
|
<code>[/boot](/source/%2Fboot)</code>
|Contains all the files needed for successful booting process. In [Research Unix](/source/Research_Unix), this was one file rather than a directory.<ref name="upe"/> Nowadays usually on the root filesystem itself, unless the system, bootloader etc. require otherwise.
|-
|
<code>[/dev](/source/%2Fdev)</code>
|Stands for ''devices''. Contains [file representations](/source/device_node) of peripheral devices and [pseudo-devices](/source/Device_file). See also: [Linux Assigned Names and Numbers Authority](/source/Linux_Assigned_Names_and_Numbers_Authority). Needs to be on the root filesystem itself.
|-
|
<code>/etc</code>
|Contains system-wide configuration files and system databases; the name stands for ''[et cetera](/source/et_cetera)''<ref name="upe">{{cite book |first1=Brian W. |last1=Kernighan |author-link1=Brian Kernighan |first2=Rob |last2=Pike |author-link2=Rob Pike |title=The UNIX Programming Environment |publisher=Prentice-Hall |year=1984 |pages=[https://archive.org/details/unixprogramminge0000kern/page/63 63–65]|title-link=The UNIX Programming Environment |bibcode=1984upe..book.....K }}</ref> but now a better expansion is '''e'''ditable-'''t'''ext-'''c'''onfigurations. Originally also contained "dangerous maintenance utilities" such as <code>init</code>,<ref name="v7"/> but these have typically been moved to <code>/sbin</code> or elsewhere. Needs to be on the root filesystem itself.
|-
|
<code>/home</code>
|Contains user home directories on Linux and some other systems. In the original version of Unix, home directories were in <code>/usr</code> instead.<ref name="notes72">{{cite web|last=Ritchie|first=Dennis|title=Unix Notes from 1972|url=https://www.nokia.com/bell-labs/about/dennis-m-ritchie/notes.html|access-date=7 September 2025}}</ref> Some systems use or have used different locations still: [macOS](/source/macOS) has home directories in <code>/Users</code>, older versions of BSD put them in <code>/u</code>, [FreeBSD](/source/FreeBSD) has <code>/usr/home</code>.
|-
|
<code>/lib</code>
|Originally ''essential libraries'': [C](/source/C_(programming_language)) libraries, but not [Fortran](/source/Fortran) ones.<ref name="upe"/> On modern systems, it contains the shared libraries needed by programs in <code>/bin</code>, and possibly [loadable kernel module](/source/loadable_kernel_module), [device driver](/source/device_driver)s or [binary blob](/source/binary_blob)s. Linux distributions may have variants <code>/lib32</code> and <code>/lib64</code> for multi-architecture support.
|-
|
<code>/media</code>
|Default mount point for removable devices, such as USB sticks, media players, etc. By common sense, the directory itself, whose subdirectories are mountpoints, is on the root partition itself.
|-
|
<code>/mnt</code>
|Stands for ''mount''. Empty directory commonly used by system administrators as a temporary mount point. By common sense, the directory itself, whose subdirectories are mountpoints, is on the root partition itself.
|-
|
<code>/opt</code>
|Contains locally installed software. Originated in [System V](/source/System_V), which has a [package manager](/source/package_manager) that installs software to this directory (one subdirectory per package).<ref>''[http://www.sco.com/developers/devspecs/gabi41.pdf System V Application Binary Interface]'' Edition 4.1 (1997-03-18)</ref>
|-
|
<code>/proc</code>
|[procfs](/source/procfs) [synthetic file system](/source/synthetic_file_system) showing information about [processes](/source/process_(computing)) as files.
|-
|
<code>/root</code>
|The home directory for the [superuser](/source/superuser) ''root'' - that is, the system administrator. This account's home directory is usually on the initial filesystem, and hence not in /home (which may be a mount point for another filesystem) in case specific maintenance needs to be performed, during which other filesystems are not available. Such a case could occur, for example, if a hard disk drive suffers failures and cannot be properly mounted.
|-
|
<code>/sbin</code>
|Stands for "[system (or superuser) binaries](/source/computer_program)" and contains fundamental utilities, such as <code>init</code>, usually needed to start, maintain and recover the system. Needs to be on the root partition itself.
|-
|
<code>/srv</code>
|Server data (data for services provided by system).
|-
|
<code>/sys</code>
|In some [Linux distribution](/source/Linux_distribution)s, contains a [sysfs](/source/sysfs) [synthetic file system](/source/synthetic_file_system), containing information related to hardware and the operating system. On BSD systems, commonly a [symlink](/source/symlink) to the kernel sources in <code>/usr/src/sys</code>.
|-
|
<code>/tmp</code>
|A place for temporary files not expected to survive a reboot. Many systems clear this directory upon startup or use [tmpfs](/source/tmpfs) to implement it.
|-
|
<code>/unix</code>
|The Unix [kernel](/source/kernel_(operating_system)) in Research Unix and [System V](/source/System_V).<ref name="upe"/> With the addition of [virtual memory](/source/virtual_memory) support to [3BSD](/source/Berkeley_Software_Distribution), this got renamed <code>/vmunix</code>.
|-
|
<code>/usr</code>
|In the earliest versions of Unix, <code>/usr</code> was the directory holding user home directories; the directory name reflected that.<ref name="notes72"/> By the Third Edition of [Research Unix](/source/Research_Unix), ca. 1973, the operating system's programs overflowed the 256K fixed-head drive containing <code>/bin</code>, so a <code>/usr/bin</code> directory was created on the disk containing <code>/usr</code> to hold some commands; commands and user home directories both resided on <code>/usr</code>.<ref name="reader">{{cite web |author-link=Doug McIlroy |author=M. D. McIlroy |date=1987 |url=http://www.cs.dartmouth.edu/~doug/reader.pdf |title=A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 |id=CSTR 139 |publisher=Bell Labs}}</ref> Additional directories, such as <code>/usr/lib</code> and <code>/usr/tmp</code>, were also created under <code>/usr</code>; it now holds executables, libraries, and shared resources that are not system critical, such as the [X Window System](/source/X_Window_System), [window manager](/source/window_manager)s, [scripting language](/source/scripting_language)s, etc. In older Unix systems, user home directories might still appear in <code>/usr</code> alongside directories containing those items; some systems have moved user home directories under a directory other than <code>/usr</code>.
|-
|
<code>/usr/include</code>
|Stores the development headers used throughout the system. [Header file](/source/Header_file)s are mostly used by the <code>#include</code> directive in [C](/source/C_(programming_language)) language, which historically is how the name of this directory was chosen.
|-
|
<code>/usr/lib</code>
|Stores the needed libraries and data files for programs stored within <code>/usr</code> or elsewhere.
|-
|
<code>/usr/libexec</code>
|Holds programs meant to be executed by other programs rather than by users directly. E.g., the [Sendmail](/source/Sendmail) executable may be found in this directory.<ref>{{cite web |url=http://docs.cray.com/books/S-2341-22/html-S-2341-22/z1028736068smg.html |website=[UNICOS](/source/UNICOS)/mp Networking Facilities Administration |publisher=[Cray](/source/Cray) |title=Chapter 7. sendmail |access-date=14 September 2013 |archive-date=9 November 2017 |archive-url=https://web.archive.org/web/20171109075438/http://docs.cray.com/books/S-2341-22/html-S-2341-22/z1028736068smg.html |url-status=dead }}</ref> Not present in the FHS until 2011;<ref>{{cite web |url=http://bzr.linuxfoundation.org/loggerhead/lsb/devel/fhs-spec/revision/44 |title=fhs-spec revision 44 |access-date=2016-07-14 |archive-date=2017-03-05 |archive-url=https://web.archive.org/web/20170305015621/http://bzr.linuxfoundation.org/loggerhead/lsb/devel/fhs-spec/revision/44 |url-status=dead }}</ref> Linux distributions have traditionally moved the contents of this directory into <code>/usr/lib</code>, where they also resided in 4.3BSD.
|-
|
<code>/usr/local</code>
|Resembles <code>/usr</code> in structure, but its subdirectories are used for additions not part of the operating system distribution, such as custom programs or files from a [BSD](/source/BSD) [Ports collection](/source/Ports_collection). Usually has subdirectories such as <code>/usr/local/lib</code> or <code>/usr/local/bin</code>.
|-
|
<code>/usr/share</code>
|Architecture-independent program data. On Linux and modern BSD derivatives, this directory has subdirectories such as <code>man</code> for [manpage](/source/manpage)s, that used to appear directly under <code>/usr</code> in older versions.
|-
|
<code>/var</code>
|Stands for ''variable''. A place for files that might change frequently - especially in size, for example e-mail sent to users on the system, or process-ID [lock file](/source/lock_file)s.
|-
|
<code>/var/log</code>
|Contains system log files.
|-
|
<code>/var/mail</code>
|The place where all incoming mail is stored. Users (other than <code>root</code>) can access their own mail only. Often, this directory is a [symbolic link](/source/symbolic_link) to <code>/var/spool/mail</code>.
|-
|
<code>/var/spool</code>
|[Spool](/source/spooling) directory. Contains print jobs, mail spools and other queued tasks.
|-
|
<code>/var/src</code>
|The place where the uncompiled source code of some programs is.
|-
|
<code>/var/tmp</code>
|The <code>/var/tmp</code> directory is a place for temporary files which should be preserved between system reboots.
|}

==See also==
*[Btrfs](/source/Btrfs)
*[ext2](/source/ext2)
*[ext3](/source/ext3)
*[ext4](/source/ext4)
*[Filesystem Hierarchy Standard](/source/Filesystem_Hierarchy_Standard)
*[HAMMER](/source/HAMMER_(file_system))
*[JFS (file system)](/source/JFS_(file_system))
*[Unix File System](/source/Unix_File_System)
*[Veritas File System](/source/Veritas_File_System)
*[ZFS](/source/ZFS)

==References==
*{{Citizendium}}
{{Reflist|30em}}

{{Unix}}

{{DEFAULTSORT:Unix Directory Structure}}
Category:Unix file system technology
Category:File system management

---
Adapted from the Wikipedia article [Unix filesystem](https://en.wikipedia.org/wiki/Unix_filesystem) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Unix_filesystem?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
