So, you've taken the plunge and installed Linux. Congratulations! You've taken the first step on a long but very rewarding journey, and we're here to help. If you've come from a Windows or Macintosh background, you're going to be faced with some potentially unfamiliar concepts that are essential to using the system effectively. Let's get started by talking about a very important concept: the Linux directory structure.
If you've come from, say, a Windows background, you're used to certain types of files being in certain locations. Linux is no different in this respect, except that the locations are different. You may find the Linux way of doing things more preferable, simply because files are arranged in a more logical hierarchy.
The first thing to note is that in a directory path, directory and file names are separated by forward slashes ("/") instead of backslashes. In Linux, directories are arranged in a tree-like structure, starting with what is known as the "root," or top-most directory. The root directory is represented by a single forward slash. Underneath it are the main system directories. To display the contents of the root directory, we can use the "ls" (list) command, specifying the root directory:
tom@murdock:~$ ls /
The output of that command will include the following directories:
Now, let's talk about the significance of these items.
- "/bin" - contains essential system commands and programs (in machine-readable format, or "binary" format, which is what "bin" stands for), such as "ls," "cp" (used to copy files), "mv" (used to move files to a different location), and so on. It also contains "bash," which is most likely the shell you are currently using. The shell is a program that allows you to issue commands to the operating system and view their output. When you are working in a terminal window, you are using the shell.
- "/boot" - contains files necessary for booting the system. If you're not familiar with this term, it describes the process of starting the system when it is powered on or restarted. During this process, a number of things happen. These might include checking the integrity of your disks, detecting hardware and getting it ready for use by the system, and starting essential programs that help to keep the system running. Also, the kernel (the "guts" of your system) may be stored in "/boot".
- "/dev" - contains files which represent system devices, such as your hard disks, serial ports, mouse, etc. For example, "/dev/hda" represents the first IDE device on your system, usually your hard drive. If this sounds confusing, don't worry -- understanding what is in this directory is the most important part.
- "/etc" - contains essential system-wide configuration files. When administering your system, you'll frequently be editing files in this directory. They control many system services and settings. Some examples of files in this directory are "/etc/resolv.conf" (contains your nameserver information) and "/etc/fstab" (a table of devices or directories that hold data and need to be accessed by the system, such as your hard drive or a CD-ROM drive). Program-specific configuration files may be here as well, and are usually identified by the letters "rc" at the end of the filename, for "run commands." An example of this might be "/etc/vimrc" (a system-wide configuration file for the vim text editor).
- "/home" - contains the home directories for all regular users. A home directory is where a user generally stores personal files. For example, if your username is "tom," then your home directory is "/home/tom." A convenient shortcut for referring to your home directory is "~/" (a tilde, followed by a forward slash). So, for the user "tom," "~/mp3/moby.mp3" actually refers to the file "/home/tom/mp3/moby.mp3".
- "/lib" - contains system libraries. Libraries are files that contain program code that is common to several applications. For example, a common thing that a program might need to do is write out to a file somewhere on disk. Rather than have to include that code in every program they write, programmers can simply point to a specific library which contains that functionality. Libraries help to keep programs smaller, more efficient, and easier to maintain. Another thing you'll find in this directory, under "/lib/modules/(kernel-version)" are your kernel modules. Modules usually serve as device drivers -- that is, they provide the necessary interface for "talking" to your system hardware, such as a network card or a SCSI CD-ROM drive.
- "/mnt" - contains "mount points," which are the locations you would use to access files on various different media such as floppies or CD-ROMs. For example, "/mnt/floppy" would be where you would usually access your floppy. All this is defined by the "/etc/fstab" file mentioned above.
- "/proc" - contains files with system information. For example, "/proc/cpuinfo" has information about your computer's processor, and "/proc/modules" lists which kernel modules are currently loaded in the system.
- "/root" - contains the "root" user's home directory.
- "/sbin" - contains commands used by the superuser ("root") for system administration. These include commands such as "shutdown" (used to shutdown or reboot the system) and fsck (a tool for checking and repairing the data on your hard disk, similar to "scandisk" on Windows).
- "/tmp" - a place to put temporary files. Applications use this directory often, which can be accessed by all users on the system.
- "/usr" - contains a number of important subdirectories. "/usr/bin" contains the bulk of the programs on your system. "/usr/sbin" contains important commands for system administration that are not already in "/sbin." So, why the difference between "/bin" and "/usr/bin", or "/sbin" and "/usr/sbin"? Well, "/bin" and "/sbin" should contain all the commands necessary for getting the system up and running, without being connected to the network. This allows "/usr" to actually be located on another computer on the network, and remotely accessed. Now, let's take a look at the rest of the "/usr" subdirectories. "/usr/lib" contains more system libraries, (as discussed above). "/usr/include" contains additional common pieces of code, similar to libraries, but used when compiling software. Compiling software is the process of taking "source code" (the human-readable instructions written by programmers using a programming language, such as C), and using a special program called a "compiler" to create a file that can be understood by the computer, called a binary file. "/usr/src" contains source code stored on the system (such as the Linux kernel source, or source code that you may have downloaded so that you can compile a program by hand). Finally, "/usr/local" contains programs and data files that have been added locally to the system, and are intended to be kept separate from the main system directories.
- "/var" - contains administrative files (such as system logs), and data that changes frequently (such as incoming mail and news).
Well, this concludes our tour of the Linux directory structure. Consider it your "roadmap" for moving around on the system. Hopefully, it will assist you in finding your way around more easily. In the future, we'll discuss basic commands for working with files and directories. In the meantime, if you have ideas for an article you'd like to see on the FirstStep section, send an email to email@example.com
Tom Dominico (firstname.lastname@example.org) is a programmer, database administrator, and Linux convert. Cursed with insomnia, he spends his sleepless nights chatting on IRC, tweaking his Linux box, and reading everything he can get his hands on.