What Do All Those Directories Do?

Heather/Squishy

Summer has finally arrived at my doorstep and I couldn't be happier... except for the fact that this also brings hay fever. I just can't win. Oh well, I'm sure others who start to use Linux (and even some old-timers) feel the same way when confronted with the myriad directory structure that Linux uses.

I mean come on, who memorizes what goes into the /usr folder? Or who can remember that if you have media devices they always get mounted to media:// or /mnt? Then again, I think I just answered my own question haven't I? Well let this be a warning to anyone reading this that this is what you get after using Linux for a while: you become a silly old maid who has nothing better to do than to memorize useless bits of information about directory structures, media file descriptors and other bits 'n' bobs we could do without in our grey matter space.

Now, in the interest of educating the wanna-be geeks (and geekettes, if that is even a word), I'm going to introduce you to some of these directories and their functions. I'm going to paste a lot of the information I have acquired from a document I found here: http://www.pathname.com/fhs/. I downloaded their latest PDF file and perused it for my cut 'n' paste episode. If you're a serious wanna-be you'll download and read their useful (if very, very dry) PDF too. Bonus points go to those who can memorize at least half of the 52 pages available.

If you're not a developer, don't worry about trying to understand or memorize all the files that go into the folders we're going to cover in this article. Where I feel its appropriate to do so, I will point out the folders a normal user should pay attention to as we go along. I will skim over some directories and just paste what is necessary to understand its contents in those instances, as some of this information is only useful to a very small portion of the audience of my column. (To that small portion: If you want to go into more detail about these areas of the filesystem, I do strongly recommend the FHS PDF file. Even though it's not written very well, it covers a lot of stuff I can't get into in my monthly column.)

Now we have a bit of background, let's start with the / (root) folder. We will get to the /root folder at the end of this article, which is separate from the aforementioned / folder. According to the FHS handbook this is what / should contain:

"The contents of the root filesystem must be adequate to boot, restore, recover, and/or repair the system ... To enable recovery and/or repair of a system, those utilities needed by an experienced maintainer to diagnose and reconstruct a damaged system must be present on the root file system."

In English this means that the / folder itself, by convention, has to be able to store a properly constructed mini-OS, and the tools to fix things in case of borkage. (Yes borkage is a real word... somewhere... in some language... it just means breakage beyond possible repair, at least in my lexicon.)

On to /bin. This directory is important to anyone who has ever had a system that is unbootable or is in need of serious repair requiring you to go into single-user mode. As outlined below, you can see where the tools needed to repair your borked computer reside.

"/bin contains commands that may be used by both the system administrator and by users, but which are required when no other file systems are mounted (e.g. in single user mode). It may also contain commands which are used indirectly by scripts."

On a related note, there are some other directories that you likely will encounter if you administer your own system. These are /sbin, /usr/sbin, and /usr/local/sbin. Their contents and purposes are described as:

"Utilities used for system administration (and other root-only commands) are stored in /sbin, /usr/sbin, and /usr/local/sbin. /sbin contains binaries essential for booting, restoring, recovering, and/or repairing the system in addition to the binaries in /bin. Programs executed after /usr is known to be mounted (when there are no problems) are generally placed into /usr/sbin. Locally-installed system administration programs should be placed into /usr/local/sbin."

At this point we have covered what are, to most users, the five directories they will encounter most often in any Linux distribution. However there are many more that are equally important.

This next directory, /boot, is not used as a separate partition much anymore. However some old time users still prefer a separate /boot partition on their system. This is sometimes the case if you wish to, for example, triple boot Fedora, Mandriva and PCLOS but want to keep all of their boot files in one directory separated into sub-directories within the /boot folder itself. According to the FHS this is what /boot should have in it:

"This directory contains everything required for the boot process except configuration files not needed at boot time and the map installer. Thus /boot stores data that is used before the kernel begins executing user-mode programs."

The /dev folder is a weird directory most users will never need to touch where your devices, like printers, usually reside:

"The /dev directory is the location of special or device files."

Now we get to the /etc folder. This is a very special folder where a system's configuration files should reside. If you have ever needed to hand edit a samba.conf file or your network interfaces file, likely it is in a sub-directory of the /etc directory. This is the FSH definition:

"/etc: Host-specific system configuration. The /etc hierarchy contains configuration files. A "configuration file" is a local file used to control the operation of a program; it must be static and cannot be an executable binary."

You may encounter, in other distros, an /etc/opt and/or an /opt folder, which is supposed to contain "...configuration files for add-on application software package [sic]". As this folder doesn't exist and is unnecessary on most distros today, I won't go into it further.

It is a fairly rare occurrence that a user will need to access the /lib directory, but I'm including it here just so you might know what exactly it contains. Shared libraries are very much like dll files in a Windows system. From the handbook:

"The /lib directory contains those shared library images [and kernel modules:H/S] needed to boot the system and run the commands in the root file system, I.E. by binaries in /bin and /sbin."

On your PCLOS system, if you open the "Storage Devices" folder on your KDE desktop, you'll be brought to a folder that lists all your hard drives' partitions and removable media. The directory this all resides under is called /media. This folder is not, that I know of, in common use yet on other distros but I find it very convenient and much easier for nublets to understand as opposed to the old /mnt folders. Our guide says:

"This directory contains subdirectories which are used as mount points for removable media such as floppy disks, cdroms and zip disks."

Another very large directory that every Linux distro out there has is called /usr. It has a boatload of subdirectories such as /usr/bin, /usr/lib, /usr/local, /usr/share, /usr/local/share, /usr/sbin, /usr/share/man, /usr/src. I will not quote the dialogue for all of these folders, but I will quote the information, for both /usr itself and /usr/share/man, below:

"/usr is the second major section of the file system. /usr is shareable, read-only data. That means that /usr should be shareable between various FHS-compliant hosts and must not be written to. Any information that is host-specific or varies with time is stored elsewhere."

And on /usr/share/man:

"This section details the organization for manual pages throughout the system, including /usr/share/man. ... The primary <man dir> of the system is /usr/share/man. /usr/share/man contains manual information for commands and data under the / and /usr file systems.

Manual pages are stored in <man dir>/<locale>/man<section>/<arch>."

As a special note to users of distros other than PCLOS: On some recent distros, the dev teams have been superceding the ancient manual pages with the newer, and presumably easier to write, info pages. These "new" man pages are often more up to date and reliable and are accessed using the – info <insert query here>: syntax. The Debian distribution is a good example of this particular quirk in Linux's evolution. Info pages are located within /usr/share/info.

The /var directory is another special directory that users will rarely access. It is called /var because it is the folder on a system that will contain the most non-static (variable, hence its name) sets of files. Normal subdirectories and files are listed below -

"/var contains variable data files. This includes spool directories and files, administrative and logging data ... [as well as] transient and temporary files. ... [Often contains] var/log, /var/lock, /var/run, /var/mail, /var/cache/man, /var/cache/fonts, and /var/spool/news."

The last two directories we're going to look at are fairly straightforward and will likely be accessed by most users at some point in their Linux journeys. These are the /root and /home directories. In the case of the /home directory, it will be used everyday.

The / and /root folders often have caused great confusion amongst the nublets I have encountered in Linux communities. (I include myself in that last remark, just so you know I'm not perfect either.) To stem the tide of confusion I'll quote the handbook about the /root folder so you can see how it is used:

"/root: Home directory for the root user (optional) The root account's home directory may be determined by developer or local preference, but this is the recommended default location."

As you can see, /root is just a glorified Home directory for the administrator of a system (usually yourself). I've found this folder is included on all of the current distributions I have used, with the exception of the micro/single purpose distros, i.e., Smoothwall (firewall distro).

This segues nicely into our final folder, the ubiquitous /home folder found on all proper Linux distributions today. I don't think I need to quote the manual for this one, so I won't bother. Suffice it to say, this is your own special directory. You can do anything you want with it and put anything you want into it without fear of it borking your system or harming other users' files on your computer. The conventional path to your /home folder is /home/your_name_here, minus the underscores (unless you really like underscores, in which case go ahead and use a few...throw in some dashes too while you're at it.) When creating your username for your system, keep in mind to never use symbolic characters if possible as some have special meaning to the Linux kernel. The exception to this is if you are using a language other than English and require characters with accents, these are perfectly fine.

Wow, if you read to the end of this column, pat yourself on the back! You now know what some of those funny folders do on your computer and how to access what is inside most of them. I hope you also have learned where to put your games and other programs you might install, or how to access your shiny new programs' manual pages and configuration files.

As always, if you have any feedback or want to ask me any questions, please email the magazine at trobins2006@gmail.com. I'll try to address any feedback that is directed to me in future columns where possible and within the space constraints of this magazine.

Until then, enjoy your summer and don't be afraid to mess with your Linux system. If something does get messed up though, just remember this: Borkage happens, time to test my remastered backup! (You did make a remastered backup didn't you?)

Top