Yesterday I covered home directories and a few commands that relate to the filesystem (namely pwd, echo, and cd). Today I will cover those mysterious and cryptic system directories.

A typical Linux system has tens of thousands of system directories. These directories contain operating system files, applications, documentation, and just about everything except private user files (which, as we covered yesterday, are located in /home).

Unless you’re a system administrator, you’ll rarely visit most system directories- but with a little knowledge you can understand or guess their purposes. Their names often contain three parts, which we’ll call the scope, category, and application. For example, the directory /usr/local/share/emacs, which contains local data for the Emacs text editor, has scope /usr/local (locally installed system files), category share (program-specific data and documentation), and application emacs (a text editor). We’ll explain these three parts, slightly out of order.

Directory Path Part 1: Category

A category tells you the types of files found in a directory. For example, if the category in bin you can be reasonably assured that the directory contains programs. Common categories are listed below.

Categories for Programs

bin Programs (usually binary files)
sbin Programs (usually binary files) intended to be run by the superuser, root
lib Libraries of code used by programs
libexec Programs invoked by other programs, not usually by users; think "library of executable programs"

Categories for Documentation

doc Documentation
info Documentation files for Emacs’s built-in help system
man Documentation files (manual pages) displayed by the man program; the files are often compressed, or sprinkled with typesetting commands for man to interpret
share Program-specific files, such as examples and installation instructions

Categories for Configuration

etc Configuration files for the system (and other miscellaneous stuff)
init.d Configuration files for booting Linux; also rc1.d, rc2.d, …
rc.d  

Categories for Programming

include Header files for programming
src Source code for programs

Categories for Web Files

cgi-bin Scripts/programs that run on web pages
html Web pages
public_html Web pages, typically in users’ home directories
www Web pages

Categories for Display

fonts Fonts
X11 X window system files

Categories for Hardware

dev Device files for interfacing with disks and other hardware
mnt Mount points: directories that provide access to disks
misc  

Categories for Runtime Files

var Files specific to this computer, created and updated as the computer runs
lock Lock files, created by programs to say, "I am running;" the existence of a lock file may prevent another program, or another instance of the same program, from running or performing an action
log Log files that track important system events, containing error, warning, and informational messages
mail Mailboxes for incoming mail
run PID files, which contain the IDs of running processes; these files are often consulted to track or kill particular processes
spool Files queued or in transit, such as outgoing email, print jobs, and scheduled jobs
tmp Temporary storage for programs and/or people to use
proc Operating system state

Directory Path Part 2: Scope

The scope of a directory path describes, at a high level, the purpose of an entire directory hierarchy. Some common ones are:

/ System files supplied with Linux (pronounced "root")
/usr More system files supplied with Linux (pronounced "user")
/usr/games Games!
/usr/kerberos Files pertaining to the Kerberos authentication system
/usr/local System files developed "locally," either for your organization or your individual computer
/usr/X11R6 Files pertaining to the X window system

So for a category like lib (libraries), your Linux system might have directories /lib, /usr/lib, /usr/local/lib, /usr/games/lib, and /usr/X11R6/lib. You might have other scopes as suits the system administrator: /my-company/lib, /mydivision/lib, and so on.

There isn’t a clear distinction between / and /usr in practice, but there is a sense that / is “lower-level” and closer to the operating system. So /bin contains fundamental programs like ls and cat, /usr/bin contains a wide variety of applications supplied with your Linux distribution, and /usr/local/bin contains programs your system administrator chose to install. These are not hard-and-fast rules, but typical cases.

Directory Path Part 3: Application

The application part of a directory path is usually the name of a program. After the scope and category (say, /usr/local/doc), a program may have its own subdirectory (say, /usr/local/doc/myprogram) containing files it needs.

Related posts: