ifacethoughts

Purpose Behind The Linux Directory Structure

A friend, who is trying Linux because of my pestering, recently ranted that the Linux directory structure was confusing. There were too many directories like /bin, /sbin, /usr/bin, /usr/local/bin, /opt and ~/bin where applications binaries could exist. Unlike the Windows systems, where usually the Program Files folder hosted all the applications, here there was a decision to be made while installing the applications. I nodded and sat down to explain the purpose behind this complexity.

Of course in most distributions today the package managers take care of installing applications in the right places, you hardly need to worry about it. However, this can help if you do try an application without an installer or install applications by hand.

The directory structure reflects the fact that Unix-based systems are built for multiple users right from the start. You see that thought influencing almost all decisions being made for the OS. In fact, the directory structure is based on a standard called Filesystem Hierarchy Standard (FHS). Reading the standard can be cumbersome, this Wikipedia page has made it easier to handle.

You can see there is an effort to separate the system software and explicit space has been provided for the user to install his/her applications and applications that will be shared amongst users. Where this brings us is that if you want to install an application that you think others can use can go in the /usr/local. If you do not want others to access it at all, you can install it in your home directory itself.

One problem that I have faced is that the structure always separates the binaries, library files and the configuration files. What if all these files are provided under one application directory? These applications can usually go in the /opt directory as a package.

These directories are separated so that different people have different permissions and access. For example, in corporate environments, only the administrator would get rights to install an application anywhere outside the home directory. However for personal computers usually you end up being the administrator and have access for everything. The directory structure is important and provides more value only in a networked multiuser case.

Another associated question I have been asked many times is to find a file particular to any application. With the files distributed across directories this can become cumbersome. You can of course use the GUI to find the file or use the command locate [filename] to find it.

Try not to write in the /bin and /sbin directories since they contain system files. As a first recommendation I would ask you to use the package managers since they hide these complexities. And secondly I would ask you to install it in any of the binary directories if the decisions are making it difficult for you. What you need to make sure is that they are in your path of execution so that your OS can find them.

Discussion [Participate or Link]

  1. Prem Kurian Philip said:

    The Linux directory structure is actually a mess. Quite often the libraries get installed into /usr/local/lib instead of into /usr/lib. Also, the /usr/local/lib path does not get added into the ld path and must be set by hand.

    /var folder doesn’t make much sense either.

    /etc directory is a mess too. It is hard to see what is a script and what is just a config file. Also, each configuration file has a completely different format. Also, the decision about what should be kept in /etc/ and what should be kept in subdirectories underneath /etc/ is not clear.

    Gobolinux (http://www.gobolinux.org) has a fresh approach to this. They have their own directory structure which seems to make more sense.

  2. Abhijit Nadgouda said:

    Prem, thanks for your comment.

    Gobolinux does have a unique approach and is probably suitable for a personal computer. But with my experience, I think the FHS makes it easy to participate in networks, with various other systems.

    Regarding the various folders, I do not think it is a mess. /usr/lib is supposed to hold system files, so application files we install later should go into /usr/local/lib. /var is used to hold stuff like log files. A separate directory for this let you give appropriate permissions.

    I think it is really a personal choice. Ideally I would prefer a packaging/installation system which handled all these complexities from the user. The user really need not worry about where some installation should go, the installer should.

Say your thought!

Who are you?

If you want to use HTML you can use these tags: <a>, <em>, <strong>, <abbr>, <code>, <blockquote>. Closing the tags will be appreciated as this site uses valid XHTML.

This is the weblog of Abhijit Nadgouda where he writes down his thoughts on software development and related topics. You are invited to subscribe to the feed to stay updated or check out more subscription options. Or you can choose to browse by one of the topics.