Understanding the Linux File System

Like any other operating system, Linux organizes information in files and directories. The files, in turn, are contained in directories. A directory can contain other directories, giving rise to a hierarchical structure. This hierarchical organization of files is called the file system.

The Linux file system provides a unified model of all storage in the system. The file system has a single root directory, indicated by a forward slash (/). Then there is a hierarchy of files and directories. Parts of the file system can reside in different physical media, such as hard disk, floppy disk, and CD-ROM. Figure 7-3 illustrates the concept of the Linux file system and how it spans multiple physical devices.

CD-ROM Hard Disk Floppy Disk

Figure 7-3: The Linux File System Provides a Unified View of Storage That May Span Multiple Drives.

If you are familiar with Windows, notice that there is no concept of a drive letter in UNIX. You can have long filenames (up to 256 characters), and filenames are case sensitive. Often, UNIX filenames have multiple extensions, such as sample.tar.Z. Some UNIX filenames include the following: index.html, Makefile, kernel-devel-2.6.11-1.1177 _FC4.i686.rpm, .bash_profile,and httpd_src.tar.gz.

To locate a file, you need more than just the file's name; you also need information about the directory hierarchy. The term pathname refers to the complete specification necessary to locate a file — the complete hierarchy of directories leading to the file — and the filename. Figure 7-4 shows a typical Linux pathname for a file.

First-level Second-level Third-level

directory directory directory Filename


f \

/ ho










ml k

Root Directory separator Name Extension directory

Root Directory separator Name Extension directory

Figure 7-4: A Typical Linux Pathname.

As you can see from Figure 7-4, a Linux pathname consists of the following parts:

1. The root directory, indicated by a forward slash (/) character.

2. The directory hierarchy, with each directory name separated from the previous one by a forward slash (/) character. A / appears after the last directory name.

3. The filename, with a name and one or more optional extensions.

Many directories have specific purposes. If you know the purpose of specific directories, finding your way around Linux directories is easier. Another benefit of knowing the typical use of directories is that you can guess where to look for specific types of files when you face a new situation. Table 7-2 briefly describes the directories in a Linux system.

Linux follows the File System Hierarchy (FHS) standard for its file system layout and organization. FHS provides a set of requirements and guidelines for file and directory placement in any UNIX-like operating system, including Linux. An FHS-compliant file system makes it easy for users as well as software applications to locate specific files and directories because everything is in its expected place in the file system.

FHS is based on two basic characteristics of files —whether they are shareable or unshareable and whether they are static or variable. Shareable files are stored in one place, but may be used by many applications on the same computer or even other systems on the network. Unshareable files are ones that are exclusive to one process (an example of an unshareable file is a device lock file that indicates that a process is using the device). Static files include binaries, libraries, documentation files, and other files that are not changed by applications or users on a routine basis (static files are typically updated by the system administrator when needed). Variable files, on the other hand, are files that applications update and change. For example, error logs and mail spools are examples variable files. The idea is to organize the directories so that static and variable files are segregated because static files, unlike variable files, can be stored on read-only media and do not need to be backed up as often as variable files.

The current version of FHS is 2.3 and it was released on January 29, 2004. To learn more about the latest version of FHS, visit the Filesystem Hierarchy Standard home page at www.pathname.com/fhs/.

Table 7-2: Linux System Directories

Directory Description

/ Root directory that forms the base of the file system. All files and directories are contained logically in the root directory, regardless of their physical locations.

/bin Contains the executable programs that are part of the Linux operating system. Many Linux commands, such as cat, cp, Is, more, and tar, are located in /bin.

/boot Contains the Linux kernel and other files the LILO and GRUB boot managers need (the kernel and other files can be anywhere, but it is customary to place them in the /boot directory).

/dev Contains all device files. Linux treats each device as a special file; all such files are located in the device directory /dev.

/etc Contains most system configuration files and the initialization scripts (in the

/etc/rc.d subdirectory).

/home Conventional location of the home directories of all users. User naba's home directory, for example, is /home/naba.

/lib Contains library files, including the loadable driver modules, needed to boot the system.

/lost+found Directory for lost files. Every disk partition has a lost+found directory.




/root /sbin


A directory for mounting file systems on removable media, such as CD-ROM drives, floppy disks, and Zip drives. Contains the /media/floppy directory for mounting floppy disks and the /media/cdrom directory for mounting the CD-ROM drive. If you have a CD recorder, you'd find a

/media/cdrecorder directory instead of /media/cdrom.

A directory for temporarily mounted file systems.

Provides a storage area for large application software packages.

A special directory that contains information about various aspects of the Linux system.

The home directory for the root user.

Contains executable files representing commands typically used for systemadministration tasks. Commands such as mount, halt, umount, and shutdown reside in the /sbin directory.

Contains data for services (such as Web and FTP) offered by this system.

A special directory that contains information about the devices, as seen by the Linux kernel.

Temporary directory that any user can use as a scratch directory, meaning that the contents of this directory are considered unimportant and usually are deleted every time the system boots.

Contains the subdirectories for many important programs, such as the X Window System, and the online manual.

Contains various system files (such as logs), as well as directories for holding other information, such as files for the Web server and anonymous FTP server.

The /usr and /var directories also contain a host of useful subdirectories. Table 7-3 lists a few of the important subdirectories in / usr. Table 7-4 shows a similar breakdown for the /var directory.

Table 7-3: Important /usr Subdirectories

Subdirectory Description

/usr/X11R6 Contains the XFree86 (X Window System) software.

/usr/bin Contains executable files for many more Linux commands, including utility programs commonly available in Linux, but is not part of the core Linux operating system.

/usr/include Contains the header files (files with names ending in .h) for the C and C++ programming languages; also includes the X11 header files in the /usr/include/X11 directory and the kernel header files in the

/usr/include/linux directory.

/usr/lib Contains the libraries for C and C++ programming languages; also contains many other libraries, such as database libraries, graphical toolkit libraries, and so on

Table 7-3: (continued)




Contains local files. The / usr/local/bin directory, for example, is

supposed to be the location for any executable program developed on your



Contains many administrative commands, such as commands for electronic

mail and networking.


Contains shared read-only architecture-independent (this means not

dependent on the processor type) data, such as default configuration files

and images for many applications. For example, /usr/share/gnome

contains various shared files for the GNOME desktop; and /usr/share/

doc has the documentation files for many Linux applications (such as the

Bash shell, mtools, and the GIMP image processing program).


Contains the online manual (which you can read by using the man command).


Contains the source code for the Linux kernel (the core operating system).

Table 7-4: Important /var Subdirectories




Storage area for cached data for applications.


Contains information relating to the current state of applications. (Programs

modify this information when they run.)


Contains lock files to ensure that a resource is used by one application only.


Contains log files organized into subdirectories. The syslogd server stores

its log files in /var/log and the exact content of the files depends on the

syslogd configuration file: /etc/syslog.conf. For example, /var/

log/messages is the main system log file, /var/log/secure contains

log messages from secure services such as sshd and xinetd, and /var/

log/maillog contains the log of mail messages.


Contains user mailbox files.


Contains variable data for packages stored in the / opt directory.


Contains data describing the system since it was booted.


Contains data that's waiting for some kind of processing.


Contains temporary files preserved between system reboots.


Contains Network Information Service (NIS) database files.

Was this article helpful?

0 0
Make Money Writing

Make Money Writing

This Report Will Show You How To Make Money By Providing Writing Services To Other Internet Marketers. Learn how to make money by writing the right way. Grab your copy of this report now and learn. Why writing is a great way to earn money. How to compete with cheap writers, even if you charge a lot more money.

Get My Free Ebook

Post a comment