<HTML ><HEAD ><TITLE >Linux Directory Hierarchy: Oriented to the Software Parts</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+ "><LINK REL="HOME" TITLE="Designing Integrated High Quality Linux Applications" HREF="index.html"><LINK REL="PREVIOUS" TITLE="The Four Universal Parts of Any Software" HREF="software.html"><LINK REL="NEXT" TITLE="Provide Architecture for Extensions and Plugins" HREF="plugin.html"></HEAD ><BODY CLASS="section" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Designing Integrated High Quality Linux Applications</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="software.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="plugin.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="fhs">4. Linux Directory Hierarchy: Oriented to the Software Parts</H1 ><P >By now, all discussion are OS independent. On Linux, the <A HREF="software.html" >Four Software Parts</A > theory is expressed in his directory structure, which is classified and documented in the <A HREF="http://www.pathname.com/fhs/" TARGET="_top" >Filesystem Hierarchy Standard</A >. The <SPAN CLASS="acronym" >FHS</SPAN > is part of the <A HREF="http://www.linuxbase.org/" TARGET="_top" ><SPAN CLASS="acronym" >LSB</SPAN > (Linux Standard Base)</A >, which makes him a good thing because all the industry is moving thowards it, and is a constant preoccupation to all distributions. <SPAN CLASS="acronym" >FHS</SPAN > defines in which directories each peace of Apache, Samba, Mozilla, KDE <EM >and your Software</EM > must go, and you don't have any other reason to not use it while thinking in developing your Software, but I'll give you some more:</P ><P ></P ><OL TYPE="1" ><LI ><P ><SPAN CLASS="acronym" >FHS</SPAN > is a standard, and we can't live without standards</P ></LI ><LI ><P >This is the most basic OS organization, that are related to access levels and <A HREF="security.html" ><STRONG >security</STRONG ></A >, where users intuitively find each type of file, etc</P ></LI ><LI ><P ><EM >Makes user's life easyer</EM ></P ></LI ></OL ><P >This last reason already justifies FHS adoption, so <SPAN CLASS="strong" ><SPAN CLASS="phrase" >allways use the <SPAN CLASS="acronym" >FHS</SPAN ></SPAN ></SPAN > !!!</P ><P >More about <SPAN CLASS="acronym" >FHS</SPAN > importance and sharing the same directory structure can be found in <A HREF="http://www.redhat.com/docs/manuals/linux/RHL-7.2-Manual/ref-guide/ch-filesystem.html" TARGET="_top" >Red Hat website.</A ></P ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="fhs.fhs">4.1. <SPAN CLASS="acronym" >FHS</SPAN > Summary</H2 ><P >So let's summarize what the <SPAN CLASS="acronym" >FHS</SPAN > has to say about Linux directories:</P ><P ></P ><DIV CLASS="variablelist" ><P ><B >Linux system directories</B ></P ><DL ><DT ><TT CLASS="filename" >/usr/bin</TT ></DT ><DD ><P >Directory for the executables that are accessed by all users (everybody have this directory in their <TT CLASS="varname" >$PATH</TT >). The main files of your Software will probably be here. You should never create a subdirectory under this folder.</P ></DD ><DT ><TT CLASS="filename" >/bin</TT ></DT ><DD ><P >Like <TT CLASS="filename" >/usr/bin</TT >, but here you'll find only boot process vital executables, that are simple and small. Your Software (being high-level) probably doesn't have nothing to install here.</P ></DD ><DT ><TT CLASS="filename" >/usr/sbin</TT ></DT ><DD ><P >Like <TT CLASS="filename" >/usr/bin</TT >, but contains only the executables that must be accessed by the administrator (root user). Regular users should never have this directory in their <TT CLASS="varname" >$PATH</TT >. If your Software is a daemon, This is the directory for some of executables.</P ></DD ><DT ><TT CLASS="filename" >/sbin</TT ></DT ><DD ><P >Like <TT CLASS="filename" >/usr/sbin</TT >, but only for the boot process vital executables, and that will be accessed by sysadmin for some system maintaining. Commands like <B CLASS="command" >fsck</B > (filesystem check), <B CLASS="command" >init</B > (father of all processes), <B CLASS="command" >ifconfig</B > (network configuration), <B CLASS="command" >mount</B >, etc can be found here. It is the system's most vital directory.</P ></DD ><DT ><TT CLASS="filename" >/usr/lib</TT ></DT ><DD ><P >Contains dynamic libraries and support static files for the executables at <TT CLASS="filename" >/usr/bin</TT > and <TT CLASS="filename" >/usr/sbin</TT >. You can create a subdirectory like <TT CLASS="filename" >/usr/lib/myproduct</TT > to contain your helper files, or dynamic libraries that will be accessed only by your Software, without user intervention. A subdirectory here can be used as a container for <A HREF="plugin.html" >plugins and extensions</A >.</P ></DD ><DT ><TT CLASS="filename" >/lib</TT ></DT ><DD ><P >Like <TT CLASS="filename" >/usr/lib</TT > but contains dynamic libraries and support static files needed in the boot process. You'll never find an executable at <TT CLASS="filename" >/bin</TT > or <TT CLASS="filename" >/sbin</TT > that needs a library that is outside this directory. Kernel modules (device drivers) are under <TT CLASS="filename" >/lib</TT >.</P ></DD ><DT ><TT CLASS="filename" >/etc</TT ></DT ><DD ><P >Contains configuration files. If your Software uses several files, put them under a subfolder like <TT CLASS="filename" >/etc/myproduct/</TT ></P ></DD ><DT ><TT CLASS="filename" >/var</TT ></DT ><DD ><P >The name comes from "<EM >variable</EM >", because everything that is under this directory changes frequently, and the package system (RPM) doesn't keep control of. Usually <TT CLASS="filename" >/var</TT > is mounted over a separate high-performance partition. In <TT CLASS="filename" >/var/log</TT > logfiles grow up. For web content we use <TT CLASS="filename" >/var/www</TT >, and so on.</P ></DD ><DT ><TT CLASS="filename" >/home</TT ></DT ><DD ><P >Contains the user's (real human beings) <EM >home</EM > directories. Your Software package should <EM >never</EM > install files here (in installation time). If <EM >your</EM > business logic requires a special <SPAN CLASS="acronym" >UNIX</SPAN > user (not a human being) to be created, you should assign him a home directory under <TT CLASS="filename" >/var</TT > or other place <EM >outside</EM > <TT CLASS="filename" >/home</TT >. Please, never forget that.</P ></DD ><DT ><TT CLASS="filename" >/usr/share/doc</TT >, <TT CLASS="filename" >/usr/share/man</TT ></DT ><DD ><P >The "share" word is used because what is under <TT CLASS="filename" >/usr/share</TT > is platform independent, and can be shared among several machines across a network filesystem. Therefore this is the place for manuals, documentations, examples etc.</P ></DD ><DT ><TT CLASS="filename" >/usr/local</TT >, <TT CLASS="filename" >/opt</TT ></DT ><DD ><P >These are obsolete folders. When <SPAN CLASS="acronym" >UNIX</SPAN > didn't have a package system (like RPM), sysadmins needed to separate an <EM >optional</EM > (or <EM >local</EM >) Software from the main OS. These were the directories used for that.</P ></DD ></DL ></DIV ><P >You may think is a bad idea to break your Software (as a whole) in many pieces, instead of keeping it all under a self-contained directory. But a <A HREF="rpm.html" >package system (RPM)</A > has a database that manages it all for you in a very professional way, taking care of configuration files, directories etc. And if you spread your Software using the <SPAN CLASS="acronym" >FHS</SPAN >, beyond the user friendliness, you'll bring an intuitive way to the sysadmin configure it, and work better with performance and security.</P ></DIV ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="newtable">4.2. Examples Using the <SPAN CLASS="acronym" >FHS</SPAN ></H2 ><P >Now that we know where each part of our software must be installed, lets review the <A HREF="software.html#partstable" >Universal Parts Table</A > applied to the <SPAN CLASS="acronym" >FHS</SPAN >.</P ><DIV CLASS="table" ><A NAME="AEN514"><P ><B >Table 2. Same Software, applying <SPAN CLASS="acronym" >FHS</SPAN ></B ></P ><TABLE BORDER="1" WIDTH="100%" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" > </TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="software.html#software.body" >Software on its Own</A ></TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="software.html#software.soul" >Configurations</A ></TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="software.html#software.content" >Content</A ></TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="software.html#software.logs" >Logs, Dumps etc</A ></TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><STRONG >Data Base Server</STRONG ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/usr/bin/</TT >, <TT CLASS="filename" >/usr/lib/</TT >, <TT CLASS="filename" >/usr/share/doc/mydb/</TT >, <TT CLASS="filename" >/usr/share/doc/mydb/examples/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/etc/mydb/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/var/db/instance1/</TT >, <TT CLASS="filename" >/var/db/instance2/</TT >, etc</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/var/db/instance1/transactions/</TT >, <TT CLASS="filename" >/var/log/db/access-instance1.log</TT >, <TT CLASS="filename" >/var/log/db/access-instance2.log</TT ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><STRONG >Text Editor</STRONG ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/usr/bin/</TT >, <TT CLASS="filename" >/usr/lib/</TT >, <TT CLASS="filename" >/usr/lib/myeditor/plugins/</TT >, <TT CLASS="filename" >/usr/share/myeditor/templates/</TT >, <TT CLASS="filename" >/usr/share/doc/myeditor/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >$HOME/.myeditor.conf</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >$HOME/Docs/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >$HOME/.myeditor-tmp/</TT ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><STRONG >MP3 Generator</STRONG ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/usr/bin/</TT >, <TT CLASS="filename" >/usr/lib/</TT >, <TT CLASS="filename" >/usr/lib/mymp3/plugins/</TT >, <TT CLASS="filename" >/usr/share/doc/mymp3/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >$HOME/.mymp3.conf</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >$HOME/Music/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >$HOME/.mymp3-tmp/</TT ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><STRONG >Web Server</STRONG ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/usr/sbin/</TT >, <TT CLASS="filename" >/usr/bin/</TT >, <TT CLASS="filename" >/usr/lib/httpd-modules/</TT >, <TT CLASS="filename" >/usr/share/doc/httpd/</TT >, <TT CLASS="filename" >/usr/share/doc/httpd/examples/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/etc/httpd/</TT >, <TT CLASS="filename" >/etc/httpd/instance1/</TT >, <TT CLASS="filename" >/etc/httpd/instance2/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/var/www/</TT >, <TT CLASS="filename" >/var/www/instance1/</TT >, <TT CLASS="filename" >/var/www/instance2/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/var/logs/httpd/</TT >, <TT CLASS="filename" >/var/logs/httpd/instance1/</TT >, <TT CLASS="filename" >/var/logs/httpd/instance2/</TT ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><STRONG >E-Mail Server</STRONG ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/usr/sbin/</TT >, <TT CLASS="filename" >/usr/bin/</TT >, <TT CLASS="filename" >/usr/lib/</TT >, <TT CLASS="filename" >/usr/share/doc/mymail/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/etc/mail/</TT >, <TT CLASS="filename" >/etc/mailserver.cf</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/var/mail/</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="filename" >/var/spool/mailqueue/</TT >, <TT CLASS="filename" >/var/logs/mail.log</TT ></TD ></TR ></TBODY ></TABLE ></DIV ></DIV ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="noopt">4.3. Developer, Do Not Install in <TT CLASS="filename" >/opt</TT > or <TT CLASS="filename" >/usr/local</TT > !</H2 ><P >If you are a systems administrator, this section is not for you. This is a subject for developers and packagers, to make sysadmin's life easyer.</P ><P >The <TT CLASS="filename" >/opt</TT > and <TT CLASS="filename" >/usr/local</TT > directories are used by sysadmins to manualy non-packaged files (without RPM) of a software, precisely to not loose control over those files. Notice how separated this folder are from the rest of the system.</P ><P >A manual installation process (without RPM, or based on simple file copy) is documented in forgoten document inside a drawer (if it was documented), and inside the head of who made installation. If he moves to another job, that installations becomes obscure to the rest of the team, and is a time bomb.</P ><P >With <A HREF="rpm.html" >RPM</A > is different. RPM (or any other package system) is an installation "process" by itself. It is self-documented in his database and pre and post-install actions, which permits total control. Turns installations independent from who did it, turning installtions in a <EM >business process</EM >.</P ><P >Installations based on coping files into <TT CLASS="filename" >/opt</TT > or <TT CLASS="filename" >/usr/local</TT > are far from providing the organization, system visibility and control that RPM provides. I can say <TT CLASS="filename" >/opt</TT > and <TT CLASS="filename" >/usr/local</TT > would be obsoleted when all softwares become RPMized.</P ><P >It is very important to Linux evolution and popularization (especially in the desktop battlefield), that developers stop using this hell directories, and start using the <SPAN CLASS="acronym" >FHS</SPAN >. After reading this section, if you still think this folders are good business, please drop me an e-mail.</P ><P >Products that are <EM >entirely</EM > installed under <EM >one</EM > directory, use the <EM >self-contained</EM > approach, that has several problems:</P ><P ></P ><OL TYPE="1" ><LI ><P >Forces the user to change environment variables like <TT CLASS="varname" >$PATH</TT > and <TT CLASS="varname" >$LD_LIBRARY_PATH</TT > to use your product easily.</P ></LI ><LI ><P >Puts files in non-standard places, complicating system integration, and future installation of extensions to your product.</P ></LI ><LI ><P >The sysadmin probably didn't prepared disk space in these partitions, generating problems in installation time.</P ></LI ><LI ><P >It is an accepted approach only for pure graphical application, without the command line concept. This is why it were well accepted in Windows. But...</P ></LI ><LI ><P >...even using this approach, you can't avoid installing or changing files in standard locations to, for instance, make your icons appear in the user desktop.</P ></LI ></OL ><P >Many developers believe that the "self-contained" approach let them work with several versions of the same product, for testing purposes, or whatever. Yes, agree, with this or any good reason in the planet. But remember that a High Quality Software (or Commercial Grade Software) objective is to be practical for the final user, and not to be easy to their developers and testers. Invite yourself to visit an unexperienced user (but potential customer) and watch him installing your product.</P ><P >Developer, don't be afraid of spreading your files according to <A HREF="fhs.html" ><SPAN CLASS="acronym" >FHS</SPAN ></A > because RPM will keep an eye on them.</P ><P >If you have a business reason to let the user work with several versions of your Product simultaneously (or any other reason), make a <A HREF="http://www.rpm.org/max-rpm/ch-rpm-reloc.html" TARGET="_top" >relocatable package</A >, which is described in the <A HREF="http://www.rpm.org/max-rpm/" TARGET="_top" >Maximum RPM</A > book. Be also aware about the implications of using this feature, <A HREF="http://www.rpm.org/max-rpm/s1-rpm-reloc-wrinkles.html" TARGET="_top" >described in the same book</A >.</P ><P >Red Hat and derivated distributions allways use the directory standard, instead of <TT CLASS="filename" >/opt</TT > or <TT CLASS="filename" >/usr/local</TT >. <A HREF="redhat.html" >Read what Red Hat says about this subject</A >, and think about it.</P ><DIV CLASS="note" ><P ></P ><TABLE CLASS="note" WIDTH="100%" BORDER="0" ><TR ><TD WIDTH="25" ALIGN="CENTER" VALIGN="TOP" ><IMG SRC="../images/note.gif" HSPACE="5" ALT="Note"></TD ><TD ALIGN="LEFT" VALIGN="TOP" ><P >The Makefiles of an OpenSource Software that is portable to other <SPAN CLASS="acronym" >UNICES</SPAN > must have the standard installation in <TT CLASS="filename" >/usr/local</TT > for compatibility reasons. But must also give the option, and induct the packager, to create the package using <A HREF="fhs.html" ><SPAN CLASS="acronym" >FHS</SPAN ></A > specifications.</P ></TD ></TR ></TABLE ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="software.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="plugin.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >The Four Universal Parts of Any Software</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" > </TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Provide Architecture for Extensions and Plugins</TD ></TR ></TABLE ></DIV ></BODY ></HTML >