{"id":2609,"date":"2012-04-25T08:30:07","date_gmt":"2012-04-25T12:30:07","guid":{"rendered":"http:\/\/www.databook.bz\/?page_id=2609"},"modified":"2019-09-16T09:26:48","modified_gmt":"2019-09-16T13:26:48","slug":"filesystem-hierarchy-standard","status":"publish","type":"page","link":"http:\/\/www.linux-databook.info\/?page_id=2609","title":{"rendered":"Linux Filesystem Hierarchical Standard"},"content":{"rendered":"<p>The actual structure of the Linux (or Unix) filesystem, that is the names and layout of the directories in the filesystem, appear to be random and complex. In reality the historical usage and structure has been somewhat random in the past, depending at least in part upon the standards and practices of individual organizations and the specific lineage of the Unix or Linux version in use.<\/p>\n\n\n<h2 class=\"wp-block-heading\">The Importance of Standardization<\/h2>\n\n\n\n<p>The primary reason to standardize the directory structure and usage of the Linux filesystem is to make life easier for the system administrator. Knowing where to look for files by usage or type makes one&#8217;s life much easier. This is especially true when many different Linux distributions can be running side by side in the same organization. Consistency makes it easier for system administrators to switch between distributions when working.<\/p>\n\n\n\n<p> As a usually very organized Virgo, I like things stored in smaller, organized groups rather than in one big bucket.  The use of directories helps me to store and then locate the files I want when I want them. Directories are also known as folders because they can be thought of as folders in which files are kept in a sort of physical desktop analogy.  <\/p>\n\n\n\n<p>\nIn\nLinux, and many other operating systems, directories can be\nstructured in a tree-like hierarchy. The Linux directory structure is\nwell defined and documented in the Linux Filesystem Hierarchy\nStandard (FHS)<a href=\"#sdfootnote1sym\"><sup>1<\/sup><\/a>.\nThis standard has been put in place to ensure that all distributions\nof Linux are consistent in their directory usage. Such consistency\nmakes writing and maintaining shell and compiled programs easier for\nSysAdmins because the programs, their configuration files, and their\ndata, if any, should be located in the standard directories. \n<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The standard<\/h2>\n\n\n\n<p>\nThe\nlatest Filesystem Hierarchical Standard (3.0)<a href=\"#sdfootnote2sym\"><sup>2<\/sup><\/a>\nis defined in a document maintained by the Linux Foundation<a href=\"#sdfootnote3sym\"><sup>3<\/sup><\/a>.\nThe document is available in multiple formats from their web site, as\nare historical versions of the FHS. I suggest that you set aside some\ntime and at least scan the entire document in order to better\nunderstand the roles played by the many subdirectories of these\ntop-level ones.<\/p>\n\n\n\n<p>\nFigure\n19-2 provides a list of the standard, well known, and defined\ntop-level Linux directories and their purposes. These directories are\nlisted in alphabetical order. <\/p>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th>\n\t\t\t\tDirectory\n\t\t\t<\/th><th>\n\t\t\t\tPart of \/\n\t\t\t<\/th><th>\n\t\t\t\tDescription\n\t\t\t<\/th><\/tr><\/thead><tbody><tr><td>\n\t\t\t\t\/ (root filesystem)\n\t\t\t<\/td><td>\n\t\t\t\tYes\n\t\t\t<\/td><td>\n\t\t\t\tThe root filesystem is the top-level directory of the filesystem.\n\t\t\t\tIt must contain all of the files required to boot the Linux\n\t\t\t\tsystem before other filesystems are mounted. After the system is\n\t\t\t\tbooted, all other filesystems are mounted on standard, well\n\t\t\t\tdefined, mount points as subdirectories of the root filesystem.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/bin\n\t\t\t<\/td><td>\n\t\t\t\tYes\n\t\t\t<\/td><td>\n\t\t\t\tThe \/bin directory contains user executable files.<a href=\"#sdfootnote4sym\"><sup>4<\/sup><\/a>\n\t\t\t\t\t\t\t\t\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/boot\n\t\t\t<\/td><td>\n\t\t\t\tNo\n\t\t\t<\/td><td>\n\t\t\t\tContains the static bootloader and kernel executable and\n\t\t\t\tconfiguration files required to boot a Linux computer.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/dev\n\t\t\t<\/td><td>\n\t\t\t\tYes\n\t\t\t<\/td><td>\n\t\t\t\tThis directory contains the device files for every hardware\n\t\t\t\tdevice attached to the system. These are not device drivers,\n\t\t\t\trather they are files that represent each device on the computer\n\t\t\t\tand facilitate access to those devices.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/etc\n\t\t\t<\/td><td>\n\t\t\t\tYes\n\t\t\t<\/td><td>\n\t\t\t\tContains a wide variety of system configuration files for the\n\t\t\t\thost computer.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/home\n\t\t\t<\/td><td>\n\t\t\t\tNo\n\t\t\t<\/td><td>\n\t\t\t\tHome directory storage for user files. Each user has a\n\t\t\t\tsubdirectory in \/home.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/lib\n\t\t\t<\/td><td>\n\t\t\t\tYes\n\t\t\t<\/td><td>\n\t\t\t\tContains shared library files that are required to boot the\n\t\t\t\tsystem.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/media\n\t\t\t<\/td><td>\n\t\t\t\tNo\n\t\t\t<\/td><td>\n\t\t\t\tA place to mount external removable media devices such as USB\n\t\t\t\tthumb drives that may be connected to the host.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/mnt\n\t\t\t<\/td><td>\n\t\t\t\tNo\n\t\t\t<\/td><td>\n\t\t\t\tA temporary mountpoint for regular filesystems (as in not\n\t\t\t\tremovable media) that can be used while the administrator is\n\t\t\t\trepairing or working on a filesystem.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/opt\n\t\t\t<\/td><td>\n\t\t\t\tNo\n\t\t\t<\/td><td>\n\t\t\t\tOptional files such as vendor supplied application programs\n\t\t\t\tshould be located here.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/proc\n\t\t\t<\/td><td>\n\t\t\t\tVirtual\n\t\t\t<\/td><td>\n\t\t\t\tVirtual filesystem used to expose access to internal kernel\n\t\t\t\tinformation and editable tuning parameters.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/root\n\t\t\t<\/td><td>\n\t\t\t\tYes\n\t\t\t<\/td><td>\n\t\t\t\tThis is not the root (\/) filesystem. It is the home directory for\n\t\t\t\tthe root user.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/sbin\n\t\t\t<\/td><td>\n\t\t\t\tYes\n\t\t\t<\/td><td>\n\t\t\t\tSystem binary files. These are executables used for system\n\t\t\t\tadministration.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/selinux\n\t\t\t<\/td><td>\n\t\t\t\tVirtual\n\t\t\t<\/td><td>\n\t\t\t\tThis filesystem is only used when SELinux is enabled. \n\t\t\t\t\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/sys\n\t\t\t<\/td><td>\n\t\t\t\tVirtual\n\t\t\t<\/td><td>\n\t\t\t\tThis virtual filesystem contains information about the USB and\n\t\t\t\tPCI busses and the devices attached to each.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/tmp\n\t\t\t<\/td><td>\n\t\t\t\tNo\n\t\t\t<\/td><td>\n\t\t\t\tTemporary directory. Used by the operating system and many\n\t\t\t\tprograms to store temporary files. Users may also store files\n\t\t\t\there temporarily. Note that files stored here may be deleted at\n\t\t\t\tany time without prior notice.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/usr\n\t\t\t<\/td><td>\n\t\t\t\tNo\n\t\t\t<\/td><td>\n\t\t\t\tThese are shareable, read only files including executable\n\t\t\t\tbinaries and libraries, man[ual] files, and other types of\n\t\t\t\tdocumentation.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/usr\/local\n\t\t\t<\/td><td>\n\t\t\t\tNo\n\t\t\t<\/td><td>\n\t\t\t\tThese are typically shell programs or compiled programs and their\n\t\t\t\tsupporting configuration files that are written locally and used\n\t\t\t\tby the SysAdmin or other users of the host.\n\t\t\t<\/td><\/tr><tr><td>\n\t\t\t\t\/var\n\t\t\t<\/td><td>\n\t\t\t\tNo\n\t\t\t<\/td><td>\n\t\t\t\tVariable data files are stored here. This can include things like\n\t\t\t\tlog files, MySQL and other database files, web server data files,\n\t\t\t\temail inboxes, and much more.\n\t\t\t<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\n<em>Figure\n19-2: The top level of the Linux Filesystem Hierarchical Standard. <\/em>\n<\/p>\n\n\n\n<p>\nThe\ndirectories shown in Figure 19-2, along with their subdirectories,\nthat have a Yes in column 2 are considered to be an integral part of\nthe root filesystem. That is, they cannot be created as a separate\nfilesystem and mounted at startup time. This is because they,\nspecifically their contents, must be present at boot time in order\nfor the system to boot properly. The \/media and \/mnt directories are\npart of the root filesystem, but they should never contain any data.\nRather, they are simply temporary mount points.<\/p>\n\n\n\n<p>\nThe\nrest of the directories do not need to be present during the boot\nsequence, but will be mounted later, during the startup sequence that\nprepares the host to perform useful work. \n<\/p>\n\n\n\n<p>\nWikipedia\nalso has a good description of the FHS<a href=\"#sdfootnote5sym\"><sup>5<\/sup><\/a>.\nThis standard should be followed as closely as possible to ensure\noperational and functional consistency. Regardless of the filesystem\ntypes, i.e., EXT4, XFS, etc., used on a host, this hierarchical\ndirectory structure is the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resources<\/h2>\n\n\n\n<p><a href=\"#sdfootnote1anc\">1<\/a>Linux\n\tFoundation, <em>Linux Filesystem Hierarchical Standard<\/em>,\n\t<a href=\"http:\/\/refspecs.linuxfoundation.org\/fhs.shtml\">http:\/\/refspecs.linuxfoundation.org\/fhs.shtml<\/a>\n\t\t<\/p>\n\n\n\n<p><a href=\"#sdfootnote2anc\">2<\/a>\n\t<a href=\"http:\/\/refspecs.linuxfoundation.org\/fhs.shtml\">http:\/\/refspecs.linuxfoundation.org\/fhs.shtml<\/a>\n\t\t<\/p>\n\n\n\n<p><a href=\"#sdfootnote3anc\">3<\/a>\n\tThe Linux Foundation maintains documents defining many Linux\n\tstandards. It  also sponsors the work of Linus Torvalds.<\/p>\n\n\n\n<p><a href=\"#sdfootnote4anc\">4<\/a>Note\n\tthat \/bin and \/sbin are now just links to \/usr\/bin and \/usr\/sbin,\n\trespectively. They are no longer generally split into \u201cessential\u201d\n\tand \u201cnon-essential\u201d as they used to be. \n\t<\/p>\n\n\n\n<p><a href=\"#sdfootnote5anc\">5<\/a>Wikipedia,\n\t<em>Filesystem Hierarchy Standard<\/em>,\n\t<a href=\"https:\/\/en.wikipedia.org\/wiki\/Filesystem_Hierarchy_Standard\">https:\/\/en.wikipedia.org\/wiki\/Filesystem_Hierarchy_Standard<\/a>\n\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The actual structure of the Linux (or Unix) filesystem, that is the names and layout of the directories in the filesystem, appear to be random and complex. In reality the historical usage and structure has been somewhat random in the&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/www.linux-databook.info\/?page_id=2609\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":412,"menu_order":13,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-2609","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/2609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2609"}],"version-history":[{"count":7,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/2609\/revisions"}],"predecessor-version":[{"id":5519,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/2609\/revisions\/5519"}],"up":[{"embeddable":true,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/412"}],"wp:attachment":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}