Jump to content

Unix filesystem: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Undid revision 880962765 by J0rd1 (talk) - they're *supposed* to be aligned that way; subdirectories of /usr and /var should be indented under the entries for /usr and /var.
Undid revision 1212200380 by Chris~enwiki (talk) - programs are, but source code is, and this is referring to the location of the source code, not of the programs.
 
(44 intermediate revisions by 34 users not shown)
Line 1: Line 1:
{{Short description|Directory structure used by a Unix-like operating system}}
{{Redirect|Usr||USR (disambiguation){{!}}USR}}
{{Redirect|Usr||USR (disambiguation){{!}}USR}}
{{Redirect|Unix file system|UFS, a specific file system used by many Unix and Unix-like operating systems|Unix File System}}
{{Redirect|Unix file system|UFS, a specific file system used by many Unix and Unix-like operating systems|Unix File System}}
Line 4: Line 5:
[[File:Standard-unix-filesystem-hierarchy.svg|thumb|An overview of a [[Unix]] filesystem layout]]
[[File:Standard-unix-filesystem-hierarchy.svg|thumb|An overview of a [[Unix]] filesystem layout]]


In [[Unix]] and [[operating system]]s inspired by it, the [[file system]] is considered a central component of the operating system.<ref name=" Ritchie">{{cite journal |last1= Ritchie |first1= D.M. |authorlink1= Dennis Ritchie |last2= Thompson |first2= K. |authorlink2= Ken Thompson |title= The UNIX Time-Sharing System |journal= Bell System Tech. J. |volume= 57 |issue= 6 |pages= 1905–1929 |publisher= AT&T |location= USA |date= July 1978 |archiveurl= https://archive.org/details/bstj57-6-1905 |archivedate= 19 January 2013 |url= http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=6770404 |doi=10.1002/j.1538-7305.1978.tb02136.x}}</ref> It was also one of the first parts of the system to be designed and implemented by [[Ken Thompson]] in the first experimental version of Unix, [[History of Unix|dated 1969]].<ref name="evolution"/>
In [[Unix]] and [[operating system]]s inspired by it, the [[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]] in the first experimental version of Unix, [[History of Unix|dated 1969]].<ref name="evolution"/>


As in other operating systems, the filesystem provides information storage and retrieval, and one of several forms of [[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 [[Pipeline (Unix)|pipes]] complemented it in this role starting with the [[Research Unix|Third Edition]]. Also, the filesystem provides access to other resources through so-called ''[[device file]]s'' that are entry points to [[computer terminal|terminals]], [[computer printer|printers]], and [[computer mouse|mice]].
As in other operating systems, the filesystem provides information storage and retrieval, and one of several forms of [[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 [[Pipeline (Unix)|pipes]] complemented it in this role starting with the [[Research Unix|Third Edition]]. Also, the filesystem provides access to other resources through so-called ''[[device file]]s'' that are entry points to [[computer terminal|terminals]], [[computer printer|printers]], and [[computer mouse|mice]].
Line 13: Line 14:
The filesystem appears as one [[rooted tree]] of directories.<ref name="Ritchie"/> Instead of addressing separate volumes such as [[Disk partitioning|disk partitions]], removable media, and [[network share]]s as separate trees (as done in [[DOS]] and [[Microsoft Windows|Windows]]: each ''drive'' has a drive letter that denotes the root of its file system tree), such volumes can be ''[[mount (Unix)|mounted]]'' 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>.
The filesystem appears as one [[rooted tree]] of directories.<ref name="Ritchie"/> Instead of addressing separate volumes such as [[Disk partitioning|disk partitions]], removable media, and [[network share]]s as separate trees (as done in [[DOS]] and [[Microsoft Windows|Windows]]: each ''drive'' has a drive letter that denotes the root of its file system tree), such volumes can be ''[[mount (Unix)|mounted]]'' 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 [[Research Unix|Bell Labs 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's disks contents viewable at <code>/usr</code>.
In the original [[Research Unix|Bell Labs 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>.


Unix directories do not ''contain'' files. Instead, they contain the names of files paired with references to so-called [[inode]]s, which in turn contain both the file and its [[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]]''.<ref name="Ritchie"/> The mathematical traits of hard links make the file system a limited type of [[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}}</ref>)
Unix directories do not ''contain'' files. Instead, they contain the names of files paired with references to so-called [[inode]]s, which in turn contain both the file and its [[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]]''.<ref name="Ritchie"/> The mathematical traits of hard links make the file system a limited type of [[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}}</ref>)


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


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


BSD also added [[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]],<ref name="FFS">{{cite web|last1=McKusick et al|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|accessdate=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>
BSD also added [[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]],<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==
==Conventional directory layout==
Certain conventions exist for locating some kinds of files, such as programs, system configuration files, and users' [[home directory|home directories]]. These were first documented in the <code>hier(7)</code> [[man page]] since [[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>
Certain conventions exist for locating some kinds of files, such as programs, system configuration files, and users' [[home directory|home directories]]. These were first documented in the <code>hier(7)</code> [[man page]] since [[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]], several attempts exist to standardize (parts of) it, such as the [[UNIX System V|System V]] [[Application Binary Interface]], the [[Intel Binary Compatibility Standard]], the Common Operating System Environment, and [[Linux Foundation]]'s [[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]] |date=1 November 2000 |author=George Kraft IV |accessdate=13 November 2014}}</ref>
The details of the directory layout have varied over time. Although the file system layout is not part of the [[Single UNIX Specification]], several attempts exist to standardize (parts of) it, such as the [[UNIX System V|System V]] [[Application Binary Interface]], the [[Intel Binary Compatibility Standard]], the Common Operating System Environment, and [[Linux Foundation]]'s [[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]] |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:
Here is a generalized overview of common locations of files on a Unix operating system:
Line 51: Line 52:
|
|
:<code>/etc</code>
:<code>/etc</code>
|Contains system-wide configuration files and system databases; the name stands for ''[[et cetera]]''.<ref name="upe">{{cite book |first1=Brian W. |last1=Kernighan |authorlink1=Brian Kernighan |first2=Rob |last2=Pike |authorlink2=Rob Pike |title=[[The UNIX Programming Environment]] |publisher=Prentice-Hall |year=1984 |pages=63–65}}</ref> 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.
|Contains system-wide configuration files and system databases; the name stands for ''[[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>
:<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.bell-labs.com/usr/dmr/www/notes.html|accessdate=14 January 2018}}</ref> Some systems use or have used different locations still: [[macOS]] has home directories in <code>/Users</code>, older versions of BSD put them in <code>/u</code>, [[FreeBSD]] has <code>/usr/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.bell-labs.com/usr/dmr/www/notes.html|access-date=14 January 2018}}</ref> Some systems use or have used different locations still: [[macOS]] has home directories in <code>/Users</code>, older versions of BSD put them in <code>/u</code>, [[FreeBSD]] has <code>/usr/home</code>.
|-
|-
|
|
Line 79: Line 80:
|
|
:<code>/root</code>
:<code>/root</code>
|The home directory for the [[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 physical failures and cannot be properly mounted. By convention, this directory is on the root partition itself; in any case, it is ''not'' a link to */home/root or any such thing.
|The home directory for the [[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.
|-
|-
|
|
Line 99: Line 100:
|
|
:<code>/unix</code>
:<code>/unix</code>
|The Unix [[kernel (computing)|kernel]] in Research Unix and [[UNIX System V|System V]].<ref name="upe"/> With the addition of [[virtual memory]] support to [[Berkeley Software Distribution#3BSD|3BSD]], this got renamed <code>/vmunix</code>.
|The Unix [[kernel (operating system)|kernel]] in Research Unix and [[UNIX System V|System V]].<ref name="upe"/> With the addition of [[virtual memory]] support to [[Berkeley Software Distribution#3BSD|3BSD]], this got renamed <code>/vmunix</code>.
|-
|-
|
|
:<code>/usr</code>
:<code>/usr</code>
|The "user file system": originally the directory holding user home directories,<ref name="notes72"/> but already by the Third Edition of [[Research Unix]], ca. 1973, reused to split the operating system's programs over two disks (one of them a 256K fixed-head drive) so that basic commands would either appear in <code>/bin</code> or <code>/usr/bin</code>.<ref name="reader">[[Doug McIlroy|M. D. McIlroy]] (1987). [http://www.cs.dartmouth.edu/~doug/reader.pdf A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986]. CSTR 139, Bell Labs.</ref> It now holds executables, libraries, and shared resources that are not system critical, like the [[X Window System]], [[KDE]], [[Perl]], etc. In older Unix systems, user home directories might still appear in <code>/usr</code> alongside directories containing programs, although by 1984 this depended on ''local customs''.<ref name="upe"/>
|The "user file system": originally the directory holding user home directories,<ref name="notes72"/> but already by the Third Edition of [[Research Unix]], ca. 1973, reused to split the operating system's programs over two disks (one of them a 256K fixed-head drive) so that basic commands would either appear in <code>/bin</code> or <code>/usr/bin</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> It now holds executables, libraries, and shared resources that are not system critical, such as the [[X Window System]], [[window manager]]s, [[scripting language]]s, etc. In older Unix systems, user home directories might still appear in <code>/usr</code> alongside directories containing programs, although by 1984 this depended on local customs.<ref name="upe"/>
|-
|-
|
|
::<code>/include</code>
::<code>/usr/include</code>
|Stores the development headers used throughout the system. [[Header file]]s are mostly used by the <code>#include</code> directive in [[C (programming language)|C]] language, which historically is how the name of this directory was chosen.
|Stores the development headers used throughout the system. [[Header file]]s are mostly used by the <code>#include</code> directive in [[C (programming language)|C]] language, which historically is how the name of this directory was chosen.
|-
|-
|
|
::<code>/lib</code>
::<code>/usr/lib</code>
|Stores the needed libraries and data files for programs stored within <code>/usr</code> or elsewhere.
|Stores the needed libraries and data files for programs stored within <code>/usr</code> or elsewhere.
|-
|-
|
|
::<code>/libexec</code>
::<code>/usr/libexec</code>
|Holds programs meant to be executed by other programs rather than by users directly. E.g., the [[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]]/mp Networking Facilities Administration |publisher=[[Cray]] |title=Chapter 7. sendmail |accessdate=14 September 2013}}</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}}</ref> Linux distributions have traditionally moved the contents of this directory into <code>/usr/lib</code>, where they also resided in 4.3BSD.
|Holds programs meant to be executed by other programs rather than by users directly. E.g., the [[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]]/mp Networking Facilities Administration |publisher=[[Cray]] |title=Chapter 7. sendmail |access-date=14 September 2013}}</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}}</ref> Linux distributions have traditionally moved the contents of this directory into <code>/usr/lib</code>, where they also resided in 4.3BSD.
|-
|-
|
|
::<code>/local</code>
::<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]] [[Ports collection]]. Usually has subdirectories such as <code>/usr/local/lib</code> or <code>/usr/local/bin</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]] [[Ports collection]]. Usually has subdirectories such as <code>/usr/local/lib</code> or <code>/usr/local/bin</code>.
|-
|-
|
|
::<code>/share</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]]s, that used to appear directly under <code>/usr</code> in older versions.
|Architecture-independent program data. On Linux and modern BSD derivatives, this directory has subdirectories such as <code>man</code> for [[manpage]]s, that used to appear directly under <code>/usr</code> in older versions.
|-
|-
|
|
:<code>/var</code>
:<code>/var</code>
|Stands for ''variable''. A place for files that may change often - especially in size, for example e-mail sent to users on the system, or process-ID [[lock file]]s.
|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]]s.
|-
|-
|
|
::<code>/log</code>
::<code>/var/log</code>
|Contains system log files.
|Contains system log files.
|-
|-
|
|
::<code>/mail</code>
::<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]] to <code>/var/spool/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]] to <code>/var/spool/mail</code>.
|-
|-
|
|
::<code>/spool</code>
::<code>/var/spool</code>
|[[spooling|Spool]] directory. Contains print jobs, mail spools and other queued tasks.
|[[spooling|Spool]] directory. Contains print jobs, mail spools and other queued tasks.
|-
|-
|
|
::<code>/src</code>
::<code>/var/src</code>
|The place where the uncompiled source code of some programs are.
|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==
==See also==<!-- Please keep entries in alphabetical order & add a short description [[WP:SEEALSO]] -->
{{Div col|colwidth=20em|small=yes}}
*[[Btrfs]]
*[[Btrfs]]
*[[ext2]]
*[[ext2]]
Line 153: Line 157:
*[[ext4]]
*[[ext4]]
*[[Filesystem Hierarchy Standard]]
*[[Filesystem Hierarchy Standard]]
*[[HAMMER]]
*[[HAMMER (file system)|HAMMER]]
*[[JFS (file system)]]
*[[JFS (file system)]]
*[[Unix File System]]
*[[Unix File System]]
*[[Veritas File System]]
*[[Veritas File System]]
*[[ZFS]]
*[[ZFS]]
{{div col end}}
<!-- please keep entries in alphabetical order -->


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

{{Unix}}


{{DEFAULTSORT:Unix Directory Structure}}
{{DEFAULTSORT:Unix Directory Structure}}

Latest revision as of 07:33, 17 March 2024

Version 7 Unix filesystem layout: subdirectories of "/" and "/usr"
An overview of a Unix filesystem layout

In Unix and operating systems inspired by it, the file system is considered a central component of the operating system.[1] It was also one of the first parts of the system to be designed and implemented by Ken Thompson in the first experimental version of Unix, dated 1969.[2]

As in other operating systems, the filesystem provides information storage and retrieval, and one of several forms of 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 complemented it in this role starting with the Third Edition. Also, the filesystem provides access to other resources through so-called device files that are entry points to terminals, printers, and mice.

The rest of this article uses Unix as a generic name to refer to both the original Unix operating system and its many workalikes.

Principles

[edit]

The filesystem appears as one rooted tree of directories.[1] Instead of addressing separate volumes such as disk partitions, removable media, and network shares as separate trees (as done in DOS and Windows: each drive has a drive letter that denotes the root of its file system tree), such volumes can be mounted on a directory, causing the volume's file system tree to appear as that directory in the larger tree.[1] The root of the entire tree is denoted /.

In the original Bell Labs 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 usr on the first disk, causing the two disks to appear as one filesystem, with the second disk’s contents viewable at /usr.

Unix directories do not contain files. Instead, they contain the names of files paired with references to so-called inodes, which in turn contain both the file and its 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.[1] The mathematical traits of hard links make the file system a limited type of directed acyclic graph, although the directories still form a tree, as they typically may not be hard-linked. (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.[2])

File types

[edit]

The original Unix file system supported three types of files: ordinary files, directories, and "special files", also termed device files.[1] The Berkeley Software Distribution (BSD) and System V each added a file type to be used for interprocess communication: BSD added sockets,[3] while System V added FIFO files.

BSD also added symbolic links (often termed "symlinks") to the range of file types, which are files that refer to other files, and complement hard links.[3] Symlinks were modeled after a similar feature in Multics,[4] 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.[5]

Conventional directory layout

[edit]

Certain conventions exist for locating some kinds of files, such as programs, system configuration files, and users' home directories. These were first documented in the hier(7) man page since Version 7 Unix;[6] subsequent versions, derivatives and clones typically have a similar man page.[7][8][9][10][11][12]

The details of the directory layout have varied over time. Although the file system layout is not part of the Single UNIX Specification, several attempts exist to standardize (parts of) it, such as the System V Application Binary Interface, the Intel Binary Compatibility Standard, the Common Operating System Environment, and Linux Foundation's Filesystem Hierarchy Standard (FHS).[13]

Here is a generalized overview of common locations of files on a Unix operating system:

Directory or file Description
/ The slash / character alone denotes the root of the filesystem tree.
/bin
Stands for binaries and contains certain fundamental utilities, such as ls or cp, that are needed to mount /usr, when that is a separate filesystem, or to run in one-user (administrative) mode when /usr cannot be mounted. In System V.4, this is a symlink to /usr/bin. Otherwise, it needs to be on the root filesystem itself.
/boot
Contains all the files needed for successful booting process. In Research Unix, this was one file rather than a directory.[14] Nowadays usually on the root filesystem itself, unless the system, bootloader etc. require otherwise.
/dev
Stands for devices. Contains file representations of peripheral devices and pseudo-devices. See also: Linux Assigned Names and Numbers Authority. Needs to be on the root filesystem itself.
/etc
Contains system-wide configuration files and system databases; the name stands for et cetera[14] but now a better expansion is editable-text-configurations. Originally also contained "dangerous maintenance utilities" such as init,[6] but these have typically been moved to /sbin or elsewhere. Needs to be on the root filesystem itself.
/home
Contains user home directories on Linux and some other systems. In the original version of Unix, home directories were in /usr instead.[15] Some systems use or have used different locations still: macOS has home directories in /Users, older versions of BSD put them in /u, FreeBSD has /usr/home.
/lib
Originally essential libraries: C libraries, but not Fortran ones.[14] On modern systems, it contains the shared libraries needed by programs in /bin, and possibly loadable kernel module or device drivers. Linux distributions may have variants /lib32 and /lib64 for multi-architecture support.
/media
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.
/mnt
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.
/opt
Contains locally installed software. Originated in System V, which has a package manager that installs software to this directory (one subdirectory per package).[16]
/proc
procfs virtual filesystem showing information about processes as files.
/root
The home directory for the 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.
/sbin
Stands for "system (or superuser) binaries" and contains fundamental utilities, such as init, usually needed to start, maintain and recover the system. Needs to be on the root partition itself.
/srv
Server data (data for services provided by system).
/sys
In some Linux distributions, contains a sysfs virtual filesystem, containing information related to hardware and the operating system. On BSD systems, commonly a symlink to the kernel sources in /usr/src/sys.
/tmp
A place for temporary files not expected to survive a reboot. Many systems clear this directory upon startup or use tmpfs to implement it.
/unix
The Unix kernel in Research Unix and System V.[14] With the addition of virtual memory support to 3BSD, this got renamed /vmunix.
/usr
The "user file system": originally the directory holding user home directories,[15] but already by the Third Edition of Research Unix, ca. 1973, reused to split the operating system's programs over two disks (one of them a 256K fixed-head drive) so that basic commands would either appear in /bin or /usr/bin.[17] It now holds executables, libraries, and shared resources that are not system critical, such as the X Window System, window managers, scripting languages, etc. In older Unix systems, user home directories might still appear in /usr alongside directories containing programs, although by 1984 this depended on local customs.[14]
/usr/include
Stores the development headers used throughout the system. Header files are mostly used by the #include directive in C language, which historically is how the name of this directory was chosen.
/usr/lib
Stores the needed libraries and data files for programs stored within /usr or elsewhere.
/usr/libexec
Holds programs meant to be executed by other programs rather than by users directly. E.g., the Sendmail executable may be found in this directory.[18] Not present in the FHS until 2011;[19] Linux distributions have traditionally moved the contents of this directory into /usr/lib, where they also resided in 4.3BSD.
/usr/local
Resembles /usr 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 Ports collection. Usually has subdirectories such as /usr/local/lib or /usr/local/bin.
/usr/share
Architecture-independent program data. On Linux and modern BSD derivatives, this directory has subdirectories such as man for manpages, that used to appear directly under /usr in older versions.
/var
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 files.
/var/log
Contains system log files.
/var/mail
The place where all incoming mail is stored. Users (other than root) can access their own mail only. Often, this directory is a symbolic link to /var/spool/mail.
/var/spool
Spool directory. Contains print jobs, mail spools and other queued tasks.
/var/src
The place where the uncompiled source code of some programs is.
/var/tmp
The /var/tmp directory is a place for temporary files which should be preserved between system reboots.

See also

[edit]

References

[edit]
  1. ^ a b c d e Ritchie, D.M.; Thompson, K. (July 1978). "The UNIX Time-Sharing System". Bell System Tech. J. 57 (6): 1905–1929. CiteSeerX 10.1.1.112.595. doi:10.1002/j.1538-7305.1978.tb02136.x.
  2. ^ a b Ritchie, Dennis M. (1979). The Evolution of the Unix Time-sharing System. Language Design and Programming Methodology Conf.
  3. ^ a b Leffler, Samuel J.; McKusick, Marshall Kirk; Karels, Michael J.; Quarterman, John S. (October 1989). The Design and Implementation of the 4.3BSD UNIX Operating System. Addison-Wesley. ISBN 978-0-201-06196-3.
  4. ^ McKusick, Marshall Kirk; et al. "A Fast Filesystem for Unix" (PDF). Freebsd.org. CSRG, UC Berkeley. Retrieved 16 November 2016.
  5. ^ stat(2) – Linux Programmer's Manual – System Calls
  6. ^ a b hier(7) – Version 7 Unix Programmer's Manual
  7. ^ hier(7) – FreeBSD Miscellaneous Information Manual
  8. ^ hier(7) – OpenBSD Miscellaneous Information Manual
  9. ^ "hier(7) man page for 2.9.1 BSD".
  10. ^ "hier(7) man page for ULTRIX 4.2".
  11. ^ "hier(7) man page for SunOS 4.1.3".
  12. ^ hier(7) – Linux Programmer's Manual – Overview, Conventions and Miscellanea
  13. ^ George Kraft IV (1 November 2000). "Where to Install My Products on Linux?". Linux Journal. Retrieved 13 November 2014.
  14. ^ a b c d e Kernighan, Brian W.; Pike, Rob (1984). The UNIX Programming Environment. Prentice-Hall. pp. 63–65. Bibcode:1984upe..book.....K.
  15. ^ a b Ritchie, Dennis. "Unix Notes from 1972". Retrieved 14 January 2018.
  16. ^ System V Application Binary Interface Edition 4.1 (1997-03-18)
  17. ^ M. D. McIlroy (1987). "A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986" (PDF). Bell Labs. CSTR 139.
  18. ^ "Chapter 7. sendmail". UNICOS/mp Networking Facilities Administration. Cray. Retrieved 14 September 2013.
  19. ^ "fhs-spec revision 44".