User Tools

Site Tools


products:ict:linux:directory_structure

17. Overview of the UNIX Directory Layout

Here is an overview of how UNIX directories are structured. This is a simplistic and theoretical overview and not a specification of the LINUX file system. Chapter 35 contains proper details of permitted directories and the kinds of files allowed within them.

17.1 Packages

LINUX systems are divided into hundreds of small packages, each performing some logical group of operations. On LINUX, many small, self-contained packages interoperate to give greater functionality than would large, aggregated pieces of software. There is also no clear distinction between what is part of the operating system and what is an application–every function is just a package.

A software package on a RedHat type system is distributed in a single RedHat Package Manager (RPM) file that has a .rpm extension. On a Debian distribution, the equivalent is a .deb package file, and on the Slackware distribution there are Slackware .tgz files.

Each package will unpack as many files, which are placed all over the system. Packages generally do not create major directories but unpack files into existing, well-known, major directories.

Note that on a newly installed system there are no files anywhere that do not belong to some package.

17.2 UNIX Directory Superstructure

The root directory on a UNIX system typically looks like this:

drwxr-xr-x 2 root root 2048 Aug 25 14:04 bin drwxr-xr-x 2 root root 1024 Sep 16 10:36 boot drwxr-xr-x 7 root root 35840 Aug 26 17:08 dev drwxr-xr-x 41 root root 4096 Sep 24 20:55 etc drwxr-xr-x 24 root root 1024 Sep 27 11:01 home drwxr-xr-x 4 root root 3072 May 19 10:05 lib drwxr-xr-x 2 root root 12288 Dec 15 1998 lost+found drwxr-xr-x 7 root root 1024 Jun 7 11:47 mnt dr-xr-xr-x 80 root root 0 Sep 16 10:36 proc drwxr-xr-x 3 root root 3072 Sep 23 23:41 sbin drwxrwxrwt 5 root root 4096 Sep 28 18:12 tmp drwxr-xr-x 25 root root 1024 May 29 10:23 usr

The /usr directory typically looks like this:

drwxr-xr-x 9 root root 1024 May 15 11:49 X11R6 drwxr-xr-x 6 root root 27648 Sep 28 17:18 bin drwxr-xr-x 2 root root 1024 May 13 16:46 dict drwxr-xr-x 261 root root 7168 Sep 26 10:55 doc drwxr-xr-x 7 root root 1024 Sep 3 08:07 etc drwxr-xr-x 2 root root 2048 May 15 10:02 games drwxr-xr-x 4 root root 1024 Mar 21 1999 i386-redhat-linux drwxr-xr-x 36 root root 7168 Sep 12 17:06 include drwxr-xr-x 2 root root 9216 Sep 7 09:05 info drwxr-xr-x 79 root root 12288 Sep 28 17:17 lib drwxr-xr-x 3 root root 1024 May 13 16:21 libexec drwxr-xr-x 15 root root 1024 May 13 16:35 man drwxr-xr-x 2 root root 4096 May 15 10:02 sbin drwxr-xr-x 39 root root 1024 Sep 12 17:07 share drwxr-xr-x 3 root root 1024 Sep 4 14:38 src drwxr-xr-x 3 root root 1024 Dec 16 1998 var

The /usr/local directory typically looks like this:

drwxr-xr-x 3 root root 4096 Sep 27 13:16 bin drwxr-xr-x 2 root root 1024 Feb 6 1996 doc drwxr-xr-x 4 root root 1024 Sep 3 08:07 etc drwxr-xr-x 2 root root 1024 Feb 6 1996 games drwxr-xr-x 5 root root 1024 Aug 21 19:36 include drwxr-xr-x 2 root root 1024 Sep 7 09:08 info drwxr-xr-x 9 root root 2048 Aug 21 19:44 lib drwxr-xr-x 12 root root 1024 Aug 2 1998 man drwxr-xr-x 2 root root 1024 Feb 6 1996 sbin drwxr-xr-x 15 root root 1024 Sep 7 09:08 share

and the /usr/X11R6 directory also looks similar. What is apparent here is that all these directories contain a similar set of subdirectories. This set of subdirectories is called a directory superstructure or superstructure. [To my knowledge this is a new term not previously used by UNIX administrators.]

The superstructure always contains a bin and lib subdirectory, but almost all others are optional.

Each package will install under one of these superstructures, meaning that it will unpack many files into various subdirectories of the superstructure. A RedHat package would always install under the /usr or / superstructure, unless it is a graphical X Window System application, which installs under the /usr/X11R6/ superstructure. Some very large applications may install under a /opt/<package-name> superstructure, and homemade packages usually install under the /usr/local/ superstructure ( local means specific to this very machine). The directory superstructure under which a package installs is often called the installation prefix. Packages almost never install files across different superstructures. [Exceptions to this are configuration files which are mostly stored in /etc/.]

Typically, most of the system is under /usr. This directory can be read-only, since packages should never need to write to this directory–any writing is done under /var or /tmp ( /usr/var and /usr/tmp are often just symlinked to /var or /tmp, respectively). The small amount under / that is not part of another superstructure (usually about 40 megabytes) performs essential system administration functions. These are commands needed to bring up or repair the system in the absence of /usr.

The list of superstructure subdirectories and their descriptions is as follows:

bin

  Binary executables. Usually all bin directories are in the PATH environment variable so that the shell will search all these directories for binaries. 

sbin

  Superuser binary executables. These are programs for system administration only. Only the 

root will have these executables in their PATH.

lib

  Libraries. All other data needed by programs goes in here. Most packages have their own subdirectory under lib to store data files into. Dynamically Linked Libraries (DLLs or .so files.) [Executable program code shared by more than one program in the bin directory to save disk space and memory.] are stored directly in lib. 

etc to:

Introduction In the Linux operating system, all filesystems are contained within one directory hierarchy. The root directory is the top level directory, and all its subdirectories make up the directory hierarchy. This differs to other operating systems such as MS-Windows which applies a separate hierarchy for each device and partition.

As you may have noticed, Linux organizes its files differently from Windows. First the directory structure may seem unlogical and strange and you have no idea where all the programs, icons, config files, and others are. This tuXfile will take you to a guided tour through the Linux file system. This is by no means a complete list of all the directories on Linux, but it shows you the most interesting places in your file system.

The Linux directory hierarchy at a glance The following directories are contained within the structure: Top level directory /

< / >

The root directory. The starting point of your directory structure. This is where the Linux system begins. Every other file and directory on your system is under the root directory. Usually the root directory contains only subdirectories, so it's a bad idea to store single files directly under root.

Don't confuse the root directory with the root user account, root password (which obviously is the root user's password) or root user's home directory.

LINUX systems are divided into hundreds of small packages, each performing some logical group of operations. On LINUX, many small, self-contained packages interoperate to give greater functionality than would large, aggregated pieces of software. There is also no clear distinction between what is part of the operating system and what is an application–every function is just a package.

A software package on a RedHat type system is distributed in a single RedHat Package Manager (RPM) file that has a .rpm extension. On a Debian distribution, the equivalent is a .deb package file, and on the Slackware distribution there are Slackware .tgz files. Each package will unpack as many files, which are placed all over the system. Packages generally do not create major directories but unpack files into existing, well-known, major directories. Note that on a newly installed system there are no files anywhere that do not belong to some package.

RPM packages install usually in /bin /sbin /usr/bin or /usr/sbin Compiled packages usually install in /usr/local/bin or /usr/local/sbin Packages coming form the Unix domain like applixware or Oracle sometimes install in /opt Typically, most of the system is under /usr. This directory can be read-only, since packages should never need to write to this directory–any writing is done under /var or /tmp ( /usr/var and /usr/tmp are often just symlinked to /var or /tmp, respectively). The small amount under / that is not part of another superstructure (usually about 40 megabytes) performs essential system administration functions. These are commands needed to bring up or repair the system in the absence of /usr. The list of superstructure subdirectories and their descriptions is as follows:

Note that the etc directory differs from that of a RedHat distribution. The system startup files /etc/rc.d are greatly simplified under Slackware. The init.d is different for Suse. The /lib/modules/2.6.12-12mdk/ directory contains kernel modules. There can be multiple versions of kernels so the directores are in /lib/modules. Subdirectories bin sbin lib usr var boot dev etc home mnt proc root tmp lost+found opt The Linux Filesystem Hierarchy Listed below are the directories contained within the root filesystem. / The Linux filesystem has the root directory at the top of the directory tree. The following list of directories are subdirectories of the root directory. This directory is denoted by the / (pronounced “slash”) symbol. To view the list of directories from the root directory, enter the following in the command line: $ls / You will see a list of subdirectories output to the screen. All these directories are explained below. One of the best ways to come to terms with a new operating system is to get familiar with the way that the system organizes its files. Files are usually stored in directories which are arranged in a hierarchal tree structure. This is commonly called the directory structure. Here is an example of a common Linux directory structure represented by the KDE desktop. This should look similar to what you would see with most other visual operating systems. Linux uses “The Filesystem Hierarchy Standard”. There will be slight variations but a lot of what you see here is common to many Unix-based systems. Most Linux distributions such as Red Hat, Mandrake, Suse, Debian, etc, use this file system, or at least something very close to it. It should be noted, you can build your own Linux system any way that you want (Free software by definition). There is no strict requirement that you use any particular structure, however, other users will have difficulty using your system and it could turn into a maintenance nightmare very quickly. Some of the directories shown here will be of little interest to many Linux users. For most users, other then root, their primary concern will be their home directory which can be structured any way that is convenient. Windows users will notice that there are no hard drive distinctions. The directory structure shown actually represents a system which has 3 hard drives. With Unix-based systems, drives are not shown. File systems are mounted to particular drives but for the user, the actual implementation is transparent. This approach allows files to be presented to the user in a more centralized view even though the files may actually be spread out among several hard drives and partitions. The result is better security and protection against system crashes and data loss. “/” This is a mandatory directory. It is the beginning of the filesystem and includes all of the directories beneath it. If you type cd / and then ls you will see a listing of all directories on the system (That you have permission to see). This should be similar to the graphic above. /bin This is a mandatory directory. This directory contains the binaries that are used in single-user systems. For multi-user systems these binaries are usually stored in the /usr/bin directory. When you type a command such as ls or chmod it is usually directed to one of these two directories where the program exists.

/bin

These two directories contain a lot of programs (binaries, hence the directory's name) for the system. The /bin directory contains the most important programs that the system needs to operate, such as the shells, ls, grep, and other essential things. /usr/bin in turn contains applications for the system's users. However, in some cases it really doesn't make much difference if you put the program in /bin or /usr/bin.

Binary executables. Usually all bin directories are in the PATH environment variable so that the shell will search all these directories for binaries.

/bin Contains executable programs such as ls and cp. These programs are designed to make the system usable. Programs within /bin are required for system repairing. Some of the files located in the /bin directory include: Shell programs bash sh File manipulation programs tar echo vi grep Process handling programs kill ps

/boot

As the name suggests, this is the place where Linux keeps information that it needs when booting up. For example, this is where the Linux kernel is kept. If you list the contents of /boot, you'll see a file called vmlinuz - that's the kernel. Stored in this directory are files that are required for the Linux boot process. Such files include vmlinuz, the Linux kernel file. This is a mandatory directory. This directory stores the files which are used for the system startup except for the configuration and map installer. Frequently the kernel is stored here especially if more then one kernel is installed.

/dev

This is a mandatory directory. The device files, sockets, and named pipes are stored here. Contains device files required for interfacing with hardware. Devices in UNIX are either block or character devices. Examples of character devices are your keyboard, mouse and serial port. Block devices can include the floppy drive, CD-ROM drive and hard disk. Common files in /dev include: psaux (interface to PS/2 mouse) modem (interface to modem hardware) ttyS0 (first serial port) tty0 (first virtual console). The devices that are available to a Linux system. Remember that in Linux, devices are treated like files and you can read and write devices like they were files. For example, /dev/fd0 is your first floppy drive, /dev/cdrom is your CD drive, /dev/hda is the first IDE hard drive, and so on. All the devices that a Linux kernel can understand are located under /dev, and that's why it contains hundreds of entries.

/etc Changed lines 83-84 from:

var to:

This is a mandatory directory. This directory, pronounced “et-see”, holds the configuration files for the system. It is divided into many subdirectories. Contains configuration files which are local to the machine. Programs store configuration files in this directory and these files are referenced when programs are run. Common files or directories found in /etc include: /etc/X11/ (the X Window configuration directory) profile (system-wide environment configuration file). The configuration files for the Linux system. Most of these files are text files and can be edited by hand. Some interesting stuff in this directory: /etc/inittab A text file that describes what processes are started at system bootup and during normal operation. For example, here you can determine if you want the X Window System to start automatically at bootup, and configure what happens when a user presses Ctrl+Alt+Del. /etc/fstab This file contains descriptive information about the various file systems and their mount points, like floppies, cdroms, and so on. /etc/passwd A file that contains various pieces of information for each user account. This is where the users are defined.

/home

This is where users keep their personal files. Every user has their own directory under /home, and usually it's the only place where normal users are allowed to write files. You can configure a Linux system so that normal users can't even list the contents of other users' home directories. This means that if your family members have their own user accounts on your Linux system, they won't see all the w4r3z you keep in your home directory. ;-) This is an optional but widely used directory. The other variation on the /home directory is to use a subdirectory in the /var directory. This is where users will do most of their work. Each user is given their own directory in the /home directory which is theirs to organize and use as they choose. Frequently web server document roots are located in the /home directory. (ex. /home/public_html or /home/www/public_html) The /home directory is designed to host dynamically changing files and usually occupies one of the larger partitions on a hard disk.

Contains user account directories. Each user created by the system administrator will have a subdirectory under /home with the name of the account. This is the default behaviour of Linux systems. E.g. User account for Anna is created, her home directory will be located in /home/anna. All her personal files will reside in this directory. All participants in this class are using the home directories of their respective user accounts. At Computerbank, /home is served via the network, enabling users to access their home directory from any networked machine.

/lib

  Libraries. All other data needed by programs goes in here. Most packages have their own subdirectory under lib to store data files into. Dynamically Linked Libraries (DLLs or .so files.) [Executable program code shared by more than one program in the bin directory to save disk space and memory.] are stored directly in lib. 

This is a mandatory directory. Shared libraries needed at bootup or which need to be run by top level commands are stored here. Libraries which support users are usually stored in the /usr/lib directory.

Contains shared object library files that are necessary to boot the system as well as containing files required by various programs such as rm and ls. This directory also contains modules (located in /lib/modules) which can be loaded into the kernel. Files of interest in /lib include: libm.so (shared object file used for math functions) libc.so (C programming library used for all system and library calls). Module files are located in /lib/modules/`uname -r`/kernel/ The shared libraries for programs that are dynamically linked. The shared libraries are similar to DLL's on Winblows.

/lost+found

Here Linux keeps the files that it restores after a system crash or when a partition hasn't been unmounted before a system shutdown. This way you can recover files that would otherwise have been lost. If you're completely new to Linux, you might want to learn some commands for moving around in the file system, viewing text files, or manipulating the files. In that case I suggest you take a look at the set of tuXfiles in the Introduction to the Linux command line section.

When the filesystem cannot properly identify files, the respective files are placed in this directory. If data appears to have been lost mysteriously, it is a good idea to check in this direetory (or ask your system administrator to check for you).

/mnt

Used for mounting temporary filesystems. When mounting a CD-ROM for instance, the standard mount point location is /mnt/cdrom. This directory is used for mount points. The different physical storage devices (like the hard disk drives, floppies, CD-ROM's) must be attached to some directory in the file system tree before they can be accessed. This attaching is called mounting, and the directory where the device is attached is called the mount point.

The /mnt directory contains mount points for different devices, like /mnt/floppy for the floppy drive, /mnt/cdrom for the CD-ROM, and so on. However, you're not forced to use the /mnt directory for this purpose, you can use whatever directory you wish. Actually in some distros, like Debian and SuSE, the default is to use /floppy and /cdrom as mount points instead of directories under

This is an optional but very popular directory. This directory contains mount points for external storage devices. To access a floppy disk drive you cd to mnt/floppy. Once an external drive is accessed, its file system is mounted to the host system in the /mnt directory.

/opt

This is an optional directory. It is a directory intended to contain software packages which are added to the original system. On my system it is present, but empty.

/proc

This is a special directory. Well, actually /proc is just a virtual directory, because it doesn't exist at all! It contains some info about the kernel itself. There's a bunch of numbered entries that correspond to all processes running on the system, and there are also named entries that permit access to the current configuration of the system. Many of these entries can be viewed.

This is an optional but widely used directory. It contains a virtual filesystem which is created and used by the currently running kernel. It is deleted when the system is shut down. Frequently, monitoring programs use the /proc directory to obtain information on currently running processes and other environmental information.

/root

This is an optional but widely used directory. It is often created to eliminate clutter from the “/” directory. It contains configuration files for the root user. This is the home directory for the super user (root). This directory is not viewable from user accounts. The /root directory usually contains system administration files.

The superuser's (root's) home directory. Don't confuse this with the root directory (/) of a Linux system.

/sbin

Most system administration programs are stored in these directories. In many cases you must run these programs as the root user.

Superuser binary executables. These are programs for system administration only. Only the root will have these executables in their PATH. Similar to /bin, this directory contains executable programs needed to boot the system, however the programs within /sbin are executed by the root user. Contains system maintenance programs, examples of which are: ifconfig (interface configuration, use this command to add or remove a network interface) mkfs (make a filesystem on a partition) lilo (boot loader software, tells your Master Boot Record (MBR) where to find your operating system(s). Linux Loader (LILO) stores its working files in /boot.

/var Changed lines 159-170 from:

doc

  Documentation. This directory is discussed in Chapter 16. 

man

  Manual pages. This directory is discussed in Chapter 16. 

info

  Info pages. This directory is discussed in Chapter 16. 

share

  Shared data. Architecture-independent files. Files that are independent of the hardware platform go here. This allows them to be shared across different machines, even though those machines may have a different kind of processor altogether. 

include to:

/usr

This directory contains user applications and a variety of other things for them, like their source codes, and pictures, docs, or config files they use. /usr is the largest directory on a Linux system, and some people like to have it on a separate partition. Some interesting stuff in

/usr:

/usr/doc Documentation for the user apps, in many file formats.

/usr/share Config files and graphics for many user apps.

/usr/src Source code files for the system's software, including the Linux kernel.

/usr/include Header files for the C compiler. The header files define structures and constants that are needed for building most standard programs. A subdirectory under /usr/include contains headers for the C++ compiler.

/usr/X11R6 The X Window System and things for it. The subdirectories under /usr/X11R6 may contain some X binaries themselves, as well as documentation, header files, config files, icons, sounds, and other things related to the graphical programs.

Used to store applications. When installing an application on a Debian GNU/Linux machine, the typical path to install would be /usr/local. You will notice the directory structure within /usr appears similar to the root directory structure. Some directories located within /usr include: /usr/doc - Documentation relating to the installed software programs.

/usr/bin - Executable programs that are not required for booting or repairing the system.

/usr/local/src - Source code for locally installed applications.

/usr/local

This is where you install apps and other files for use on the local machine. If your machine is a part of a network, the /usr directory may physically be on another machine and can be shared by many networked Linux workstations. On this kind of a network, the /usr/local directory contains only stuff that is not supposed to be used on many machines and is intended for use at the local machine only. Most likely your machine isn't a part of a network like this, but it doesn't mean that /usr/local is useless. If you find interesting apps that aren't officially a part of your distro, you should install them in /usr/local. For example, if the app would normally go to /usr/bin but it isn't a part of your distro, you should install it in /usr/local/bin instead. When you keep your own programs away from the programs that are included in your distro, you'll avoid confusion and keep things nice and clean.

/usr/man

  Manual pages. 

/usr/share/info

  Info pages. 

/usr/include Changed lines 201-210 from:

src to:

/usr/share

  Shared data. Architecture-independent files. Files that are independent of the hardware platform go here. This allows them to be shared across different machines, even though those machines may have a different kind of processor altogether. 

/usr/share/doc

Documentation. 

/usr/src Changed lines 213-600 from:

tmp

  Temporary files. A convenient place for a running program to create a file for temporary use. 

17.3 LINUX on a Single 1.44 Megabyte Floppy Disk

You can get LINUX to run on a 1.44 megabyte floppy disk if you trim all unneeded files off an old Slackware distribution with a 2.0.3x kernel. You can compile a small 2.0.3x kernel to about 400 kilobytes (compressed) (see Chapter 42). A file system can be reduced to 2-3 megabytes of absolute essentials and when compressed will fit into 1 megabyte. If the total is under 1.44 megabytes, then you have your LINUX on one floppy. The file list might be as follows (includes all links):

/bin /etc /lib /sbin /var /bin/sh /etc/default /lib/ld.so /sbin/e2fsck /var/adm /bin/cat /etc/fstab /lib/libc.so.5 /sbin/fdisk /var/adm/utmp /bin/chmod /etc/group /lib/ld-linux.so.1 /sbin/fsck /var/adm/cron /bin/chown /etc/host.conf /lib/libcurses.so.1 /sbin/ifconfig /var/spool /bin/cp /etc/hosts /lib/libc.so.5.3.12 /sbin/iflink /var/spool/uucp /bin/pwd /etc/inittab /lib/libtermcap.so.2.0.8 /sbin/ifsetup /var/spool/uucp/SYSLOG /bin/dd /etc/issue /lib/libtermcap.so.2 /sbin/init /var/spool/uucp/ERRLOG /bin/df /etc/utmp /lib/libext2fs.so.2.3 /sbin/mke2fs /var/spool/locks /bin/du /etc/networks /lib/libcom_err.so.2 /sbin/mkfs /var/tmp /bin/free /etc/passwd /lib/libcom_err.so.2.0 /sbin/mkfs.minix /var/run /bin/gunzip /etc/profile /lib/libext2fs.so.2 /sbin/mklost+found /var/run/utmp /bin/gzip /etc/protocols /lib/libm.so.5.0.5 /sbin/mkswap /bin/hostname /etc/rc.d /lib/libm.so.5 /sbin/mount /home/user /bin/login /etc/rc.d/rc.0 /lib/cpp /sbin/route /bin/ls /etc/rc.d/rc.K /sbin/shutdown /mnt /bin/mkdir /etc/rc.d/rc.M /usr /sbin/swapoff /bin/mv /etc/rc.d/rc.S /usr/adm /sbin/swapon /proc /bin/ps /etc/rc.d/rc.inet1 /usr/bin /sbin/telinit /bin/rm /etc/rc.d/rc.6 /usr/bin/less /sbin/umount /tmp /bin/stty /etc/rc.d/rc.4 /usr/bin/more /sbin/agetty /bin/su /etc/rc.d/rc.inet2 /usr/bin/sleep /sbin/update /dev/<various-devices> /bin/sync /etc/resolv.conf /usr/bin/reset /sbin/reboot /bin/zcat /etc/services /usr/bin/zless /sbin/netcfg /bin/dircolors /etc/termcap /usr/bin/file /sbin/killall5 /bin/mount /etc/motd /usr/bin/fdformat /sbin/fsck.minix /bin/umount /etc/magic /usr/bin/strings /sbin/halt /bin/bash /etc/DIR_COLORS /usr/bin/zgrep /sbin/badblocks /bin/domainname /etc/HOSTNAME /usr/bin/nc /sbin/kerneld /bin/head /etc/mtools /usr/bin/which /sbin/fsck.ext2 /bin/kill /etc/ld.so.cache /usr/bin/grep /bin/tar /etc/psdevtab /usr/sbin /bin/cut /etc/mtab /usr/sbin/showmount /bin/uname /etc/fastboot /usr/sbin/chroot /bin/ping /usr/spool /bin/ln /usr/tmp /bin/ash

Note that the etc directory differs from that of a RedHat distribution. The system startup files /etc/rc.d are greatly simplified under Slackware.

The /lib/modules directory has been stripped for the creation of this floppy. /lib/modules/2.0.36 would contain dynamically loadable kernel drivers (modules). Instead, all needed drivers are compiled into the kernel for simplicity (explained in Chapter 42).

At some point, try creating a single floppy distribution as an exercise. This task should be most instructive to a serious system administrator. At the very least, you should look through all of the commands in the bin directories and the sbin directories above and browse through the man pages of any that are unfamiliar.

The preceding file system comes from the morecram-1.3 package available from http://rute.sourceforge.net/morecram-1.3.tar.gz. It can be downloaded to provide a useful rescue and setup disk. Note that there are many such rescue disks available which are more current than morecram

Home / Tutorials / Linux Directory Structure

Linux Directory Structure

Session 2: The Linux Directory Structure

Author: Con Validas Marked up by: Andrew Stone

Revision History Revision 0.5 9/02/2003

Abstract In this session we will cover the Linux directory hierarchy. This includes the root directory and all of its subdirectories. This session follows on from Session 1: Learning to use the Linux Command Line Interface by Kylie Davies.

Table of Contents

Introduction The Linux directory hierarchy at a glance Top level directory Subdirectories The Linux Filesystem Hierarchy / /bin /boot /dev /etc /home /lib /mnt /lost+found /opt /proc /root /sbin /tmp /usr /var References

Introduction In the Linux operating system, all filesystems are contained within one directory hierarchy. The root directory is the top level directory, and all its subdirectories make up the directory hierarchy. This differs to other operating systems such as MS-Windows which applies a separate hierarchy for each device and partition.

The Linux directory hierarchy at a glance The following directories are contained within the structure:

Top level directory /

Subdirectories bin sbin lib usr var boot dev etc home mnt proc root tmp lost+found opt

The Linux Filesystem Hierarchy Listed below are the directories contained within the root filesystem.

/ The Linux filesystem has the root directory at the top of the directory tree. The following list of directories are subdirectories of the root directory. This directory is denoted by the / (pronounced “slash”) symbol. To view the list of directories from the root directory, enter the following in the command line:

$ls / You will see a list of subdirectories outputed to the screen. All these directories are explained below.

/bin Contains executable programs such as ls and cp. These programs are designed to make the system usable. Programs within /bin are required for system repairing. Some of the files located in the /bin directory include:

Shell programs

  bash
  sh 

File manipulation programs

  tar
  echo
  vi
  grep 

Process handling programs

  kill
  ps 

/boot Stored in this directory are files that are required for the Linux boot process. Such files include vmlinuz, the Linux kernel file.

/dev Contains device files required for interfacing with hardware. Devices in UNIX are either block or character devices. Examples of character devices are your keyboard, mouse and serial port. Block devices can include the floppy drive, CD-ROM drive and hard disk. Common files in /dev include:

  psaux (interface to PS/2 mouse)
  modem (interface to modem hardware)
  ttyS0 (first serial port)
  tty0 (first virtual console). 

/etc

Contains configuration files which are local to the machine. Programs store configuration files in this directory and these files are referenced when programs are run. Common files or directories found in /etc include:

  /etc/X11/ (the X Window configuration directory)
  profile (system-wide environment configuration file). 

/home Contains user account directories. Each user created by the system administrator will have a subdirectory under /home with the name of the account. This is the default behaviour of Linux systems. E.g. User account for Anna is created, her home directory will be located in /home/anna. All her personal files will reside in this directory. All participants in this class are using the home directories of their respective user accounts. At Computerbank, /home is served via the network, enabling users to access their home directory from any networked machine.

/lib Contains shared object library files that are necessary to boot the system as well as containing files required by various programs such as rm and ls. This directory also contains modules (located in /lib/modules) which can be loaded into the kernel. Files of interest in /lib include:

  libm.so (shared object file used for math functions)
  libc.so (C programming library used for all system and library calls). 

Module files are located in /lib/modules/`uname -r`/kernel/

/mnt Used for mounting temporary filesystems. When mounting a CD-ROM for instance, the standard mount point location is /mnt/cdrom. On the Debian GNU/Linux systems at Computerbank, the mount point has been changed to /cdrom.

/lost+found When the filesystem cannot properly identify files, the respective files are placed in this directory. If data appears to have been lost mysteriously, it is a good idea to check in this direetory (or ask your system administrator to check for you).

/opt Used for storing random data that has no other logical destination.

/proc Provides information about running processes and the kernel. A directory is provided for each running process. Useful system information such as the amount of Random Access Memory (RAM) available on the system as well as Central Processing Unit (CPU) speed in Megahertz (MHz) can be found within the /proc directory. The following commands will give you this information:

$ cat /proc/cpuinfo - Display CPU information of system

$ cat /proc/meminfo - Display RAM information as well as swap space capacity and usage.

/root This is the home directory for the super user (root). This directory is not viewable from user accounts. The /root directory usually contains system administration files.

/sbin Similar to /bin, this directory contains executable programs needed to boot the system, however the programs within /sbin are executed by the root user. Contains system maintenance programs, examples of which are:

  ifconfig (interface configuration, use this command to add or remove a network interface)
  mkfs (make a filesystem on a partition)
  lilo (boot loader software, tells your Master Boot Record (MBR) where to find your operating system(s). Linux Loader (LILO) stores its working files in /boot. 

/tmp This directory is used for temporary storage space. Files within this directory are often cleaned out either at boot time or by a regular job process. The Debian GNU/Linux operating system cleans up the /tmp directory at boot time. An example for using the /tmp directory in Computerbank would be when downloading the OpenOffice deb packages. By downloading these packages into the /tmp directory, the user can be assured the packages will be wiped off the system next time the machine reboots.

/usr Used to store applications. When installing an application on a Debian GNU/Linux machine, the typical path to install would be /usr/local. You will notice the directory structure within /usr appears similar to the root directory structure. Some directories located within /usr include:

  /usr/doc - Documentation relating to the installed software programs.
  /usr/bin - Executable programs that are not required for booting or repairing the system.
  /usr/local/src - Source code for locally installed applications. 

/var This directory contains files of variable file storage. Files in /var are dynamic and are constantly being written to or changed. Some directories located within /var include:

  /var/spool - files in the print queue
  /var/log - files containing logging information
  /var/run - files containing the process ID's for each current process. 

References

  The hier(7) man page.
  Filesystem Hierarchy Standard (FHS)
  http://www.pathname.com/fhs/ 

From : http://www.dynamic-apps.com/linux_directories.jsp

Linux Directory Structure

One of the best ways to come to terms with a new operating system is to get familiar with the way that the system organizes its files. Files are usually stored in directories which are arranged in a hierarchal tree structure. This is commonly called the directory structure.

Here is an example of a common Linux directory structure represented by the KDE desktop. This should look similar to what you would see with most other visual operating systems.

Linux uses “The Filesystem Hierarchy Standard”. There will be slight variations but a lot of what you see here is common to many Unix-based systems. Most Linux distributions such as Red Hat, Mandrake, Suse, Debian, etc, use this file system, or at least something very close to it. It should be noted, you can build your own Linux system any way that you want (Free software by definition). There is no strict requirement that you use any particular structure, however, other users will have difficulty using your system and it could turn into a maintenance nightmare very quickly.

Some of the directories shown here will be of little interest to many Linux users. For most users, other then root, their primary concern will be their home directory which can be structured any way that is convenient.

Windows users will notice that there are no hard drive distinctions. The directory structure shown actually represents a system which has 3 hard drives. With Unix-based systems, drives are not shown. File systems are mounted to particular drives but for the user, the actual implementation is transparent. This approach allows files to be presented to the user in a more centralized view even though the files may actually be spread out among several hard drives and partitions. The result is better security and protection against system crashes and data loss.

Lets take a look at each directory and what it is used for:

“/” This is a mandatory directory. It is the beginning of the filesystem and includes all of the directories beneath it. If you type cd / and then ls you will see a listing of all directories on the system (That you have permission to see). This should be similar to the graphic above.

/bin This is a mandatory directory. This directory contains the binaries that are used in single-user systems. For multi-user systems these binaries are usually stored in the /usr/bin directory. When you type a command such as ls or chmod it is usually directed to one of these two directories where the program exists.

/boot This is a mandatory directory. This directory stores the files which are used for the system startup except for the configuration and map installer. Frequently the kernel is stored here especially if more then one kernel is installed.

/dev This is a mandatory directory. The device files, sockets, and named pipes are stored here.

/etc This is a mandatory directory. This directory, pronounced “et-see”, holds the configuration files for the system. It is divided into many subdirectories.

/home This is an optional but widely used directory. The other variation on the /home directory is to use a subdirectory in the /var directory. This is where users will do most of their work. Each user is given their own directory in the /home directory which is theirs to organize and use as they choose. Frequently web server document roots are located in the /home directory. (ex. /home/public_html or /home/www/public_html) The /home directory is designed to host dynamically changing files and usually occupies one of the larger partitions on a hard disk.

/lib This is a mandatory directory. Shared libraries needed at bootup or which need to be run by top level commands are stored here. Libraries which support users are usually stored in the /usr/lib directory.

/mnt This is an optional but very popular directory. This directory contains mount points for external storage devices. To access a floppy disk drive you cd to mnt/floppy. Once an external drive is accessed, its file system is mounted to the host system in the /mnt directory.

/opt This is an optional directory. It is a directory intended to contain software packages which are added to the original system. On my system it is present, but empty.

/proc This is an optional but widely used directory. It contains a virtual filesystem which is created and used by the currently running kernel. It is deleted when the system is shut down. Frequently, monitoring programs use the /proc directory to obtain information on currently running processes and other environmental information.

/root This is an optional but widely used directory. It is often created to eliminate clutter from the “/” directory. It contains configuration files for the root user.

/sbin This is a mandatory directory. This directory was originally a place to store static binaries. It has been expanded to include administrative binaries which are used by the root user only.

/tmp This is a mandatory directory. This directory is used by programs to store temporary files. Files which are located here are often flushed on reboot or flushed periodically.

/usr This is a mandatory directory. The /usr directory is designed to store static, sharable, read-only data. Programs which are used by all users are frequently stored here. Data which results from these programs is usually stored elsewhere (often /var).

/var This is a mandatory directory. This directory stores variable data like logs, mail, and process specific files. Most, but not all, subdirectories and files in the /var directory are shared. This is another popular location for web server document roots.

This concludes our whirlwind tour of the Linux “Filesystem Hierarchy Standard”. This standard which has been around since 1993 and provides recommendations which seek to standardize the directory structure of Linux-based systems. Most user accounts will be set up by the administrator so that the user rarely, if ever, has to venture out of their /home/username directory. System administrators are the only ones who really need to be concerned with the other directories.

Hopefully this discussion has clarified the directory structure of Linux and made the system more undersandable. Linux is really no more difficult to understand then any other operating system.

Cheers, Craig

Other Linux discussion/tutorials: Using Linux Commands Unix File Permissions Basic Vim (Vi)

From : http://www.tuxfiles.org/linuxhelp/linuxdir.html

< Linux's directory structure - 1.2 >

As you may have noticed, Linux organizes its files differently from Windows. First the directory structure may seem unlogical and strange and you have no idea where all the programs, icons, config files, and others are. This tuXfile will take you to a guided tour through the Linux file system. This is by no means a complete list of all the directories on Linux, but it shows you the most interesting places in your file system.

Author: Nana Långstedt < nana.langstedt at gmail.com > tuXfile created: 18 January 2002 Last modified: 22 September 2005 < / >

The root directory. The starting point of your directory structure. This is where the Linux system begins. Every other file and directory on your system is under the root directory. Usually the root directory contains only subdirectories, so it's a bad idea to store single files directly under root.

Don't confuse the root directory with the root user account, root password (which obviously is the root user's password) or root user's home directory. < /boot >

As the name suggests, this is the place where Linux keeps information that it needs when booting up. For example, this is where the Linux kernel is kept. If you list the contents of /boot, you'll see a file called vmlinuz - that's the kernel. < /etc >

The configuration files for the Linux system. Most of these files are text files and can be edited by hand. Some interesting stuff in this directory:

/etc/inittab A text file that describes what processes are started at system bootup and during normal operation. For example, here you can determine if you want the X Window System to start automatically at bootup, and configure what happens when a user presses Ctrl+Alt+Del.

/etc/fstab This file contains descriptive information about the various file systems and their mount points, like floppies, cdroms, and so on.

/etc/passwd A file that contains various pieces of information for each user account. This is where the users are defined. < /bin, /usr/bin >

These two directories contain a lot of programs (binaries, hence the directory's name) for the system. The /bin directory contains the most important programs that the system needs to operate, such as the shells, ls, grep, and other essential things. /usr/bin in turn contains applications for the system's users. However, in some cases it really doesn't make much difference if you put the program in /bin or /usr/bin. < /sbin, /usr/sbin >

Most system administration programs are stored in these directories. In many cases you must run these programs as the root user. < /usr >

This directory contains user applications and a variety of other things for them, like their source codes, and pictures, docs, or config files they use. /usr is the largest directory on a Linux system, and some people like to have it on a separate partition. Some interesting stuff in /usr:

/usr/doc Documentation for the user apps, in many file formats.

/usr/share Config files and graphics for many user apps.

/usr/src Source code files for the system's software, including the Linux kernel.

/usr/include Header files for the C compiler. The header files define structures and constants that are needed for building most standard programs. A subdirectory under /usr/include contains headers for the C++ compiler.

/usr/X11R6 The X Window System and things for it. The subdirectories under /usr/X11R6 may contain some X binaries themselves, as well as documentation, header files, config files, icons, sounds, and other things related to the graphical programs. < /usr/local >

This is where you install apps and other files for use on the local machine. If your machine is a part of a network, the /usr directory may physically be on another machine and can be shared by many networked Linux workstations. On this kind of a network, the /usr/local directory contains only stuff that is not supposed to be used on many machines and is intended for use at the local machine only.

Most likely your machine isn't a part of a network like this, but it doesn't mean that /usr/local is useless. If you find interesting apps that aren't officially a part of your distro, you should install them in /usr/local. For example, if the app would normally go to /usr/bin but it isn't a part of your distro, you should install it in /usr/local/bin instead. When you keep your own programs away from the programs that are included in your distro, you'll avoid confusion and keep things nice and clean. < /lib >

The shared libraries for programs that are dynamically linked. The shared libraries are similar to DLL's on Winblows. < /home >

This is where users keep their personal files. Every user has their own directory under /home, and usually it's the only place where normal users are allowed to write files. You can configure a Linux system so that normal users can't even list the contents of other users' home directories. This means that if your family members have their own user accounts on your Linux system, they won't see all the w4r3z you keep in your home directory. ;-) < /root >

The superuser's (root's) home directory. Don't confuse this with the root directory (/) of a Linux system. < /var >

This directory contains variable data that changes constantly when the system is running. Some interesting subdirectories:

/var/log A directory that contains system log files. They're updated when the system runs, and checking them out can give you valuable info about the health of your system. If something in your system suddenly goes wrong, the log files may contain some info about the situation.

/var/mail Incoming and outgoing mail is stored in this directory.

/var/spool This directory holds files that are queued for some process, like printing. < /tmp >

Programs can write their temporary files here. < /dev >

The devices that are available to a Linux system. Remember that in Linux, devices are treated like files and you can read and write devices like they were files. For example, /dev/fd0 is your first floppy drive, /dev/cdrom is your CD drive, /dev/hda is the first IDE hard drive, and so on. All the devices that a Linux kernel can understand are located under /dev, and that's why it contains hundreds of entries. < /mnt >

This directory is used for mount points. The different physical storage devices (like the hard disk drives, floppies, CD-ROM's) must be attached to some directory in the file system tree before they can be accessed. This attaching is called mounting, and the directory where the device is attached is called the mount point.

The /mnt directory contains mount points for different devices, like /mnt/floppy for the floppy drive, /mnt/cdrom for the CD-ROM, and so on. However, you're not forced to use the /mnt directory for this purpose, you can use whatever directory you wish. Actually in some distros, like Debian and SuSE, the default is to use /floppy and /cdrom as mount points instead of directories under /mnt. < /proc >

This is a special directory. Well, actually /proc is just a virtual directory, because it doesn't exist at all! It contains some info about the kernel itself. There's a bunch of numbered entries that correspond to all processes running on the system, and there are also named entries that permit access to the current configuration of the system. Many of these entries can be viewed. < /lost+found >

Here Linux keeps the files that it restores after a system crash or when a partition hasn't been unmounted before a system shutdown. This way you can recover files that would otherwise have been lost.

If you're completely new to Linux, you might want to learn some commands for moving around in the file system, viewing text files, or manipulating the files. In that case I suggest you take a look at the set of tuXfiles in the Introduction to the Linux command line section.

to:

/tmp

Temporary files. A convenient place for a running program to create a file for temporary use.

This directory is used for temporary storage space. Files within this directory are often cleaned out either at boot time or by a regular job process. The Debian GNU/Linux operating system cleans up the /tmp directory at boot time. An example for using the /tmp directory would be when downloading the OpenOffice deb packages. By downloading these packages into the /tmp directory, the user can be assured the packages will be wiped off the system next time the machine reboots.

/opt

Used for storing random data that has no other logical destination.

/proc

Provides information about running processes and the kernel. A directory is provided for each running process. Useful system information such as the amount of Random Access Memory (RAM) available on the system as well as Central Processing Unit (CPU) speed in Megahertz (MHz) can be found within the /proc directory. The following commands will give you this information:

$ cat /proc/cpuinfo - Display CPU information of system

$ cat /proc/meminfo - Display RAM information as well as swap space capacity and usage.

/sbin

This is a mandatory directory. This directory was originally a place to store static binaries. It has been expanded to include administrative binaries which are used by the root user only.

/tmp

This is a mandatory directory. This directory is used by programs to store temporary files. Files which are located here are often flushed on reboot or flushed periodically.

/usr

This is a mandatory directory. The /usr directory is designed to store static, sharable, read-only data. Programs which are used by all users are frequently stored here. Data which results from these programs is usually stored elsewhere (often /var).

/var

This directory contains files of variable file storage. Files in /var are dynamic and are constantly being written to or changed. Some directories located within

/var includes

/var/spool - files in the print queue

/var/log - files containing logging information

/var/run - files containing the process ID's for each current process.

This is a mandatory directory. This directory stores variable data like logs, mail, and process specific files. Most, but not all, subdirectories and files in the /var directory are shared. This is another popular location for web server document roots. This concludes our whirlwind tour of the Linux “Filesystem Hierarchy Standard”. This standard which has been around since 1993 and provides recommendations which seek to standardize the directory structure of Linux-based systems. Most user accounts will be set up by the administrator so that the user rarely, if ever, has to venture out of their /home/username directory. System administrators are the only ones who really need to be concerned with the other directories.

Hopefully this discussion has clarified the directory structure of Linux and made the system more undersandable. Linux is really no more difficult to understand then any other operating system. This directory contains variable data that changes constantly when the system is running. Some interesting subdirectories:

/var/log A directory that contains system log files. They're updated when the system runs, and checking them out can give you valuable info about the health of your system. If something in your system suddenly goes wrong, the log files may contain some info about the situation.

/var/mail Incoming and outgoing mail is stored in this directory.

/var/spool This directory holds files that are queued for some process, like printing. < /tmp > Programs can write their temporary files here. Changed lines 274-278 from:

Rute book Chapter 17 http://rute.2038bug.com/node20.html.gz http://doc.vic.computerbank.org.au/tutorials/linuxdirectorystructure/

to:

Rute book Chapter 17 http://rute.2038bug.com/node20.html.gz

http://doc.vic.computerbank.org.au/tutorials/linuxdirectorystructure/

Filesystem Hierarchy Standard (FHS) http://www.pathname.com/fhs/

http://www.dynamic-apps.com/linux_directories.jsp

http://www.tuxfiles.org/linuxhelp/linuxdir.html

Restore June 24, 2006, at 11:32 AM PKT by 84.11.108.4 - Changed lines 1-2 from:

From : http://doc.vic.computerbank.org.au/tutorials/linuxdirectorystructure/ to:

From :

17. Overview of the UNIX Directory Layout

Here is an overview of how UNIX directories are structured. This is a simplistic and theoretical overview and not a specification of the LINUX file system. Chapter 35 contains proper details of permitted directories and the kinds of files allowed within them.

17.1 Packages

LINUX systems are divided into hundreds of small packages, each performing some logical group of operations. On LINUX, many small, self-contained packages interoperate to give greater functionality than would large, aggregated pieces of software. There is also no clear distinction between what is part of the operating system and what is an application–every function is just a package.

A software package on a RedHat type system is distributed in a single RedHat Package Manager (RPM) file that has a .rpm extension. On a Debian distribution, the equivalent is a .deb package file, and on the Slackware distribution there are Slackware .tgz files.

Each package will unpack as many files, which are placed all over the system. Packages generally do not create major directories but unpack files into existing, well-known, major directories.

Note that on a newly installed system there are no files anywhere that do not belong to some package.

17.2 UNIX Directory Superstructure

The root directory on a UNIX system typically looks like this:

drwxr-xr-x 2 root root 2048 Aug 25 14:04 bin drwxr-xr-x 2 root root 1024 Sep 16 10:36 boot drwxr-xr-x 7 root root 35840 Aug 26 17:08 dev drwxr-xr-x 41 root root 4096 Sep 24 20:55 etc drwxr-xr-x 24 root root 1024 Sep 27 11:01 home drwxr-xr-x 4 root root 3072 May 19 10:05 lib drwxr-xr-x 2 root root 12288 Dec 15 1998 lost+found drwxr-xr-x 7 root root 1024 Jun 7 11:47 mnt dr-xr-xr-x 80 root root 0 Sep 16 10:36 proc drwxr-xr-x 3 root root 3072 Sep 23 23:41 sbin drwxrwxrwt 5 root root 4096 Sep 28 18:12 tmp drwxr-xr-x 25 root root 1024 May 29 10:23 usr

The /usr directory typically looks like this:

drwxr-xr-x 9 root root 1024 May 15 11:49 X11R6 drwxr-xr-x 6 root root 27648 Sep 28 17:18 bin drwxr-xr-x 2 root root 1024 May 13 16:46 dict drwxr-xr-x 261 root root 7168 Sep 26 10:55 doc drwxr-xr-x 7 root root 1024 Sep 3 08:07 etc drwxr-xr-x 2 root root 2048 May 15 10:02 games drwxr-xr-x 4 root root 1024 Mar 21 1999 i386-redhat-linux drwxr-xr-x 36 root root 7168 Sep 12 17:06 include drwxr-xr-x 2 root root 9216 Sep 7 09:05 info drwxr-xr-x 79 root root 12288 Sep 28 17:17 lib drwxr-xr-x 3 root root 1024 May 13 16:21 libexec drwxr-xr-x 15 root root 1024 May 13 16:35 man drwxr-xr-x 2 root root 4096 May 15 10:02 sbin drwxr-xr-x 39 root root 1024 Sep 12 17:07 share drwxr-xr-x 3 root root 1024 Sep 4 14:38 src drwxr-xr-x 3 root root 1024 Dec 16 1998 var

The /usr/local directory typically looks like this:

drwxr-xr-x 3 root root 4096 Sep 27 13:16 bin drwxr-xr-x 2 root root 1024 Feb 6 1996 doc drwxr-xr-x 4 root root 1024 Sep 3 08:07 etc drwxr-xr-x 2 root root 1024 Feb 6 1996 games drwxr-xr-x 5 root root 1024 Aug 21 19:36 include drwxr-xr-x 2 root root 1024 Sep 7 09:08 info drwxr-xr-x 9 root root 2048 Aug 21 19:44 lib drwxr-xr-x 12 root root 1024 Aug 2 1998 man drwxr-xr-x 2 root root 1024 Feb 6 1996 sbin drwxr-xr-x 15 root root 1024 Sep 7 09:08 share

and the /usr/X11R6 directory also looks similar. What is apparent here is that all these directories contain a similar set of subdirectories. This set of subdirectories is called a directory superstructure or superstructure. [To my knowledge this is a new term not previously used by UNIX administrators.]

The superstructure always contains a bin and lib subdirectory, but almost all others are optional.

Each package will install under one of these superstructures, meaning that it will unpack many files into various subdirectories of the superstructure. A RedHat package would always install under the /usr or / superstructure, unless it is a graphical X Window System application, which installs under the /usr/X11R6/ superstructure. Some very large applications may install under a /opt/<package-name> superstructure, and homemade packages usually install under the /usr/local/ superstructure ( local means specific to this very machine). The directory superstructure under which a package installs is often called the installation prefix. Packages almost never install files across different superstructures. [Exceptions to this are configuration files which are mostly stored in /etc/.]

Typically, most of the system is under /usr. This directory can be read-only, since packages should never need to write to this directory–any writing is done under /var or /tmp ( /usr/var and /usr/tmp are often just symlinked to /var or /tmp, respectively). The small amount under / that is not part of another superstructure (usually about 40 megabytes) performs essential system administration functions. These are commands needed to bring up or repair the system in the absence of /usr.

The list of superstructure subdirectories and their descriptions is as follows:

bin

  Binary executables. Usually all bin directories are in the PATH environment variable so that the shell will search all these directories for binaries. 

sbin

  Superuser binary executables. These are programs for system administration only. Only the 

root will have these executables in their PATH.

lib

  Libraries. All other data needed by programs goes in here. Most packages have their own subdirectory under lib to store data files into. Dynamically Linked Libraries (DLLs or .so files.) [Executable program code shared by more than one program in the bin directory to save disk space and memory.] are stored directly in lib. 

etc

  Et cetera. Configuration files. 

var

  Variable data. Data files that are continually being re-created or updated. 

doc

  Documentation. This directory is discussed in Chapter 16. 

man

  Manual pages. This directory is discussed in Chapter 16. 

info

  Info pages. This directory is discussed in Chapter 16. 

share

  Shared data. Architecture-independent files. Files that are independent of the hardware platform go here. This allows them to be shared across different machines, even though those machines may have a different kind of processor altogether. 

include

  C header files. These are for development. 

src

  C source files. These are sources to the kernel or locally built packages. 

tmp

  Temporary files. A convenient place for a running program to create a file for temporary use. 

17.3 LINUX on a Single 1.44 Megabyte Floppy Disk

You can get LINUX to run on a 1.44 megabyte floppy disk if you trim all unneeded files off an old Slackware distribution with a 2.0.3x kernel. You can compile a small 2.0.3x kernel to about 400 kilobytes (compressed) (see Chapter 42). A file system can be reduced to 2-3 megabytes of absolute essentials and when compressed will fit into 1 megabyte. If the total is under 1.44 megabytes, then you have your LINUX on one floppy. The file list might be as follows (includes all links):

/bin /etc /lib /sbin /var /bin/sh /etc/default /lib/ld.so /sbin/e2fsck /var/adm /bin/cat /etc/fstab /lib/libc.so.5 /sbin/fdisk /var/adm/utmp /bin/chmod /etc/group /lib/ld-linux.so.1 /sbin/fsck /var/adm/cron /bin/chown /etc/host.conf /lib/libcurses.so.1 /sbin/ifconfig /var/spool /bin/cp /etc/hosts /lib/libc.so.5.3.12 /sbin/iflink /var/spool/uucp /bin/pwd /etc/inittab /lib/libtermcap.so.2.0.8 /sbin/ifsetup /var/spool/uucp/SYSLOG /bin/dd /etc/issue /lib/libtermcap.so.2 /sbin/init /var/spool/uucp/ERRLOG /bin/df /etc/utmp /lib/libext2fs.so.2.3 /sbin/mke2fs /var/spool/locks /bin/du /etc/networks /lib/libcom_err.so.2 /sbin/mkfs /var/tmp /bin/free /etc/passwd /lib/libcom_err.so.2.0 /sbin/mkfs.minix /var/run /bin/gunzip /etc/profile /lib/libext2fs.so.2 /sbin/mklost+found /var/run/utmp /bin/gzip /etc/protocols /lib/libm.so.5.0.5 /sbin/mkswap /bin/hostname /etc/rc.d /lib/libm.so.5 /sbin/mount /home/user /bin/login /etc/rc.d/rc.0 /lib/cpp /sbin/route /bin/ls /etc/rc.d/rc.K /sbin/shutdown /mnt /bin/mkdir /etc/rc.d/rc.M /usr /sbin/swapoff /bin/mv /etc/rc.d/rc.S /usr/adm /sbin/swapon /proc /bin/ps /etc/rc.d/rc.inet1 /usr/bin /sbin/telinit /bin/rm /etc/rc.d/rc.6 /usr/bin/less /sbin/umount /tmp /bin/stty /etc/rc.d/rc.4 /usr/bin/more /sbin/agetty /bin/su /etc/rc.d/rc.inet2 /usr/bin/sleep /sbin/update /dev/<various-devices> /bin/sync /etc/resolv.conf /usr/bin/reset /sbin/reboot /bin/zcat /etc/services /usr/bin/zless /sbin/netcfg /bin/dircolors /etc/termcap /usr/bin/file /sbin/killall5 /bin/mount /etc/motd /usr/bin/fdformat /sbin/fsck.minix /bin/umount /etc/magic /usr/bin/strings /sbin/halt /bin/bash /etc/DIR_COLORS /usr/bin/zgrep /sbin/badblocks /bin/domainname /etc/HOSTNAME /usr/bin/nc /sbin/kerneld /bin/head /etc/mtools /usr/bin/which /sbin/fsck.ext2 /bin/kill /etc/ld.so.cache /usr/bin/grep /bin/tar /etc/psdevtab /usr/sbin /bin/cut /etc/mtab /usr/sbin/showmount /bin/uname /etc/fastboot /usr/sbin/chroot /bin/ping /usr/spool /bin/ln /usr/tmp /bin/ash

Note that the etc directory differs from that of a RedHat distribution. The system startup files /etc/rc.d are greatly simplified under Slackware.

The /lib/modules directory has been stripped for the creation of this floppy. /lib/modules/2.0.36 would contain dynamically loadable kernel drivers (modules). Instead, all needed drivers are compiled into the kernel for simplicity (explained in Chapter 42).

At some point, try creating a single floppy distribution as an exercise. This task should be most instructive to a serious system administrator. At the very least, you should look through all of the commands in the bin directories and the sbin directories above and browse through the man pages of any that are unfamiliar.

The preceding file system comes from the morecram-1.3 package available from http://rute.sourceforge.net/morecram-1.3.tar.gz. It can be downloaded to provide a useful rescue and setup disk. Note that there are many such rescue disks available which are more current than morecram

Changed lines 493-494 from:

< What next? > to: Changed lines 499-501 from:

to:

References : Rute book Chapter 17 http://rute.2038bug.com/node20.html.gz http://doc.vic.computerbank.org.au/tutorials/linuxdirectorystructure/

Restore June 24, 2006, at 11:27 AM PKT by 84.11.108.4 - Added lines 1-339:

From : http://doc.vic.computerbank.org.au/tutorials/linuxdirectorystructure/

Home / Tutorials / Linux Directory Structure

Linux Directory Structure

Session 2: The Linux Directory Structure

Author: Con Validas Marked up by: Andrew Stone

Revision History Revision 0.5 9/02/2003

Abstract In this session we will cover the Linux directory hierarchy. This includes the root directory and all of its subdirectories. This session follows on from Session 1: Learning to use the Linux Command Line Interface by Kylie Davies.

Table of Contents

Introduction The Linux directory hierarchy at a glance Top level directory Subdirectories The Linux Filesystem Hierarchy / /bin /boot /dev /etc /home /lib /mnt /lost+found /opt /proc /root /sbin /tmp /usr /var References

Introduction In the Linux operating system, all filesystems are contained within one directory hierarchy. The root directory is the top level directory, and all its subdirectories make up the directory hierarchy. This differs to other operating systems such as MS-Windows which applies a separate hierarchy for each device and partition.

The Linux directory hierarchy at a glance The following directories are contained within the structure:

Top level directory /

Subdirectories bin sbin lib usr var boot dev etc home mnt proc root tmp lost+found opt

The Linux Filesystem Hierarchy Listed below are the directories contained within the root filesystem.

/ The Linux filesystem has the root directory at the top of the directory tree. The following list of directories are subdirectories of the root directory. This directory is denoted by the / (pronounced “slash”) symbol. To view the list of directories from the root directory, enter the following in the command line:

$ls / You will see a list of subdirectories outputed to the screen. All these directories are explained below.

/bin Contains executable programs such as ls and cp. These programs are designed to make the system usable. Programs within /bin are required for system repairing. Some of the files located in the /bin directory include:

Shell programs

  bash
  sh 

File manipulation programs

  tar
  echo
  vi
  grep 

Process handling programs

  kill
  ps 

/boot Stored in this directory are files that are required for the Linux boot process. Such files include vmlinuz, the Linux kernel file.

/dev Contains device files required for interfacing with hardware. Devices in UNIX are either block or character devices. Examples of character devices are your keyboard, mouse and serial port. Block devices can include the floppy drive, CD-ROM drive and hard disk. Common files in /dev include:

  psaux (interface to PS/2 mouse)
  modem (interface to modem hardware)
  ttyS0 (first serial port)
  tty0 (first virtual console). 

/etc

Contains configuration files which are local to the machine. Programs store configuration files in this directory and these files are referenced when programs are run. Common files or directories found in /etc include:

  /etc/X11/ (the X Window configuration directory)
  profile (system-wide environment configuration file). 

/home Contains user account directories. Each user created by the system administrator will have a subdirectory under /home with the name of the account. This is the default behaviour of Linux systems. E.g. User account for Anna is created, her home directory will be located in /home/anna. All her personal files will reside in this directory. All participants in this class are using the home directories of their respective user accounts. At Computerbank, /home is served via the network, enabling users to access their home directory from any networked machine.

/lib Contains shared object library files that are necessary to boot the system as well as containing files required by various programs such as rm and ls. This directory also contains modules (located in /lib/modules) which can be loaded into the kernel. Files of interest in /lib include:

  libm.so (shared object file used for math functions)
  libc.so (C programming library used for all system and library calls). 

Module files are located in /lib/modules/`uname -r`/kernel/

/mnt Used for mounting temporary filesystems. When mounting a CD-ROM for instance, the standard mount point location is /mnt/cdrom. On the Debian GNU/Linux systems at Computerbank, the mount point has been changed to /cdrom.

/lost+found When the filesystem cannot properly identify files, the respective files are placed in this directory. If data appears to have been lost mysteriously, it is a good idea to check in this direetory (or ask your system administrator to check for you).

/opt Used for storing random data that has no other logical destination.

/proc Provides information about running processes and the kernel. A directory is provided for each running process. Useful system information such as the amount of Random Access Memory (RAM) available on the system as well as Central Processing Unit (CPU) speed in Megahertz (MHz) can be found within the /proc directory. The following commands will give you this information:

$ cat /proc/cpuinfo - Display CPU information of system

$ cat /proc/meminfo - Display RAM information as well as swap space capacity and usage.

/root This is the home directory for the super user (root). This directory is not viewable from user accounts. The /root directory usually contains system administration files.

/sbin Similar to /bin, this directory contains executable programs needed to boot the system, however the programs within /sbin are executed by the root user. Contains system maintenance programs, examples of which are:

  ifconfig (interface configuration, use this command to add or remove a network interface)
  mkfs (make a filesystem on a partition)
  lilo (boot loader software, tells your Master Boot Record (MBR) where to find your operating system(s). Linux Loader (LILO) stores its working files in /boot. 

/tmp This directory is used for temporary storage space. Files within this directory are often cleaned out either at boot time or by a regular job process. The Debian GNU/Linux operating system cleans up the /tmp directory at boot time. An example for using the /tmp directory in Computerbank would be when downloading the OpenOffice deb packages. By downloading these packages into the /tmp directory, the user can be assured the packages will be wiped off the system next time the machine reboots.

/usr Used to store applications. When installing an application on a Debian GNU/Linux machine, the typical path to install would be /usr/local. You will notice the directory structure within /usr appears similar to the root directory structure. Some directories located within /usr include:

  /usr/doc - Documentation relating to the installed software programs.
  /usr/bin - Executable programs that are not required for booting or repairing the system.
  /usr/local/src - Source code for locally installed applications. 

/var This directory contains files of variable file storage. Files in /var are dynamic and are constantly being written to or changed. Some directories located within /var include:

  /var/spool - files in the print queue
  /var/log - files containing logging information
  /var/run - files containing the process ID's for each current process. 

References

  The hier(7) man page.
  Filesystem Hierarchy Standard (FHS)
  http://www.pathname.com/fhs/ 

From : http://www.dynamic-apps.com/linux_directories.jsp

Linux Directory Structure

One of the best ways to come to terms with a new operating system is to get familiar with the way that the system organizes its files. Files are usually stored in directories which are arranged in a hierarchal tree structure. This is commonly called the directory structure.

Here is an example of a common Linux directory structure represented by the KDE desktop. This should look similar to what you would see with most other visual operating systems.

Linux uses “The Filesystem Hierarchy Standard”. There will be slight variations but a lot of what you see here is common to many Unix-based systems. Most Linux distributions such as Red Hat, Mandrake, Suse, Debian, etc, use this file system, or at least something very close to it. It should be noted, you can build your own Linux system any way that you want (Free software by definition). There is no strict requirement that you use any particular structure, however, other users will have difficulty using your system and it could turn into a maintenance nightmare very quickly.

Some of the directories shown here will be of little interest to many Linux users. For most users, other then root, their primary concern will be their home directory which can be structured any way that is convenient.

Windows users will notice that there are no hard drive distinctions. The directory structure shown actually represents a system which has 3 hard drives. With Unix-based systems, drives are not shown. File systems are mounted to particular drives but for the user, the actual implementation is transparent. This approach allows files to be presented to the user in a more centralized view even though the files may actually be spread out among several hard drives and partitions. The result is better security and protection against system crashes and data loss.

Lets take a look at each directory and what it is used for:

“/” This is a mandatory directory. It is the beginning of the filesystem and includes all of the directories beneath it. If you type cd / and then ls you will see a listing of all directories on the system (That you have permission to see). This should be similar to the graphic above.

/bin This is a mandatory directory. This directory contains the binaries that are used in single-user systems. For multi-user systems these binaries are usually stored in the /usr/bin directory. When you type a command such as ls or chmod it is usually directed to one of these two directories where the program exists.

/boot This is a mandatory directory. This directory stores the files which are used for the system startup except for the configuration and map installer. Frequently the kernel is stored here especially if more then one kernel is installed.

/dev This is a mandatory directory. The device files, sockets, and named pipes are stored here.

/etc This is a mandatory directory. This directory, pronounced “et-see”, holds the configuration files for the system. It is divided into many subdirectories.

/home This is an optional but widely used directory. The other variation on the /home directory is to use a subdirectory in the /var directory. This is where users will do most of their work. Each user is given their own directory in the /home directory which is theirs to organize and use as they choose. Frequently web server document roots are located in the /home directory. (ex. /home/public_html or /home/www/public_html) The /home directory is designed to host dynamically changing files and usually occupies one of the larger partitions on a hard disk.

/lib This is a mandatory directory. Shared libraries needed at bootup or which need to be run by top level commands are stored here. Libraries which support users are usually stored in the /usr/lib directory.

/mnt This is an optional but very popular directory. This directory contains mount points for external storage devices. To access a floppy disk drive you cd to mnt/floppy. Once an external drive is accessed, its file system is mounted to the host system in the /mnt directory.

/opt This is an optional directory. It is a directory intended to contain software packages which are added to the original system. On my system it is present, but empty.

/proc This is an optional but widely used directory. It contains a virtual filesystem which is created and used by the currently running kernel. It is deleted when the system is shut down. Frequently, monitoring programs use the /proc directory to obtain information on currently running processes and other environmental information.

/root This is an optional but widely used directory. It is often created to eliminate clutter from the “/” directory. It contains configuration files for the root user.

/sbin This is a mandatory directory. This directory was originally a place to store static binaries. It has been expanded to include administrative binaries which are used by the root user only.

/tmp This is a mandatory directory. This directory is used by programs to store temporary files. Files which are located here are often flushed on reboot or flushed periodically.

/usr This is a mandatory directory. The /usr directory is designed to store static, sharable, read-only data. Programs which are used by all users are frequently stored here. Data which results from these programs is usually stored elsewhere (often /var).

/var This is a mandatory directory. This directory stores variable data like logs, mail, and process specific files. Most, but not all, subdirectories and files in the /var directory are shared. This is another popular location for web server document roots.

This concludes our whirlwind tour of the Linux “Filesystem Hierarchy Standard”. This standard which has been around since 1993 and provides recommendations which seek to standardize the directory structure of Linux-based systems. Most user accounts will be set up by the administrator so that the user rarely, if ever, has to venture out of their /home/username directory. System administrators are the only ones who really need to be concerned with the other directories.

Hopefully this discussion has clarified the directory structure of Linux and made the system more undersandable. Linux is really no more difficult to understand then any other operating system.

Cheers, Craig

Other Linux discussion/tutorials: Using Linux Commands Unix File Permissions Basic Vim (Vi)

From : http://www.tuxfiles.org/linuxhelp/linuxdir.html

< Linux's directory structure - 1.2 >

As you may have noticed, Linux organizes its files differently from Windows. First the directory structure may seem unlogical and strange and you have no idea where all the programs, icons, config files, and others are. This tuXfile will take you to a guided tour through the Linux file system. This is by no means a complete list of all the directories on Linux, but it shows you the most interesting places in your file system.

Author: Nana Långstedt < nana.langstedt at gmail.com > tuXfile created: 18 January 2002 Last modified: 22 September 2005 < / >

The root directory. The starting point of your directory structure. This is where the Linux system begins. Every other file and directory on your system is under the root directory. Usually the root directory contains only subdirectories, so it's a bad idea to store single files directly under root.

Don't confuse the root directory with the root user account, root password (which obviously is the root user's password) or root user's home directory. < /boot >

As the name suggests, this is the place where Linux keeps information that it needs when booting up. For example, this is where the Linux kernel is kept. If you list the contents of /boot, you'll see a file called vmlinuz - that's the kernel. < /etc >

The configuration files for the Linux system. Most of these files are text files and can be edited by hand. Some interesting stuff in this directory:

/etc/inittab A text file that describes what processes are started at system bootup and during normal operation. For example, here you can determine if you want the X Window System to start automatically at bootup, and configure what happens when a user presses Ctrl+Alt+Del.

/etc/fstab This file contains descriptive information about the various file systems and their mount points, like floppies, cdroms, and so on.

/etc/passwd A file that contains various pieces of information for each user account. This is where the users are defined. < /bin, /usr/bin >

These two directories contain a lot of programs (binaries, hence the directory's name) for the system. The /bin directory contains the most important programs that the system needs to operate, such as the shells, ls, grep, and other essential things. /usr/bin in turn contains applications for the system's users. However, in some cases it really doesn't make much difference if you put the program in /bin or /usr/bin. < /sbin, /usr/sbin >

Most system administration programs are stored in these directories. In many cases you must run these programs as the root user. < /usr >

This directory contains user applications and a variety of other things for them, like their source codes, and pictures, docs, or config files they use. /usr is the largest directory on a Linux system, and some people like to have it on a separate partition. Some interesting stuff in /usr:

/usr/doc Documentation for the user apps, in many file formats.

/usr/share Config files and graphics for many user apps.

/usr/src Source code files for the system's software, including the Linux kernel.

/usr/include Header files for the C compiler. The header files define structures and constants that are needed for building most standard programs. A subdirectory under /usr/include contains headers for the C++ compiler.

/usr/X11R6 The X Window System and things for it. The subdirectories under /usr/X11R6 may contain some X binaries themselves, as well as documentation, header files, config files, icons, sounds, and other things related to the graphical programs. < /usr/local >

This is where you install apps and other files for use on the local machine. If your machine is a part of a network, the /usr directory may physically be on another machine and can be shared by many networked Linux workstations. On this kind of a network, the /usr/local directory contains only stuff that is not supposed to be used on many machines and is intended for use at the local machine only.

Most likely your machine isn't a part of a network like this, but it doesn't mean that /usr/local is useless. If you find interesting apps that aren't officially a part of your distro, you should install them in /usr/local. For example, if the app would normally go to /usr/bin but it isn't a part of your distro, you should install it in /usr/local/bin instead. When you keep your own programs away from the programs that are included in your distro, you'll avoid confusion and keep things nice and clean. < /lib >

The shared libraries for programs that are dynamically linked. The shared libraries are similar to DLL's on Winblows. < /home >

This is where users keep their personal files. Every user has their own directory under /home, and usually it's the only place where normal users are allowed to write files. You can configure a Linux system so that normal users can't even list the contents of other users' home directories. This means that if your family members have their own user accounts on your Linux system, they won't see all the w4r3z you keep in your home directory. ;-) < /root >

The superuser's (root's) home directory. Don't confuse this with the root directory (/) of a Linux system. < /var >

This directory contains variable data that changes constantly when the system is running. Some interesting subdirectories:

/var/log A directory that contains system log files. They're updated when the system runs, and checking them out can give you valuable info about the health of your system. If something in your system suddenly goes wrong, the log files may contain some info about the situation.

/var/mail Incoming and outgoing mail is stored in this directory.

/var/spool This directory holds files that are queued for some process, like printing. < /tmp >

Programs can write their temporary files here. < /dev >

The devices that are available to a Linux system. Remember that in Linux, devices are treated like files and you can read and write devices like they were files. For example, /dev/fd0 is your first floppy drive, /dev/cdrom is your CD drive, /dev/hda is the first IDE hard drive, and so on. All the devices that a Linux kernel can understand are located under /dev, and that's why it contains hundreds of entries. < /mnt >

This directory is used for mount points. The different physical storage devices (like the hard disk drives, floppies, CD-ROM's) must be attached to some directory in the file system tree before they can be accessed. This attaching is called mounting, and the directory where the device is attached is called the mount point.

The /mnt directory contains mount points for different devices, like /mnt/floppy for the floppy drive, /mnt/cdrom for the CD-ROM, and so on. However, you're not forced to use the /mnt directory for this purpose, you can use whatever directory you wish. Actually in some distros, like Debian and SuSE, the default is to use /floppy and /cdrom as mount points instead of directories under /mnt. < /proc >

This is a special directory. Well, actually /proc is just a virtual directory, because it doesn't exist at all! It contains some info about the kernel itself. There's a bunch of numbered entries that correspond to all processes running on the system, and there are also named entries that permit access to the current configuration of the system. Many of these entries can be viewed. < /lost+found >

Here Linux keeps the files that it restores after a system crash or when a partition hasn't been unmounted before a system shutdown. This way you can recover files that would otherwise have been lost. < What next? >

If you're completely new to Linux, you might want to learn some commands for moving around in the file system, viewing text files, or manipulating the files. In that case I suggest you take a look at the set of tuXfiles in the Introduction to the Linux command line section.

LinuxDirectoryStructure

Introduction In the Linux operating system, all filesystems are contained within one directory hierarchy. The root directory is the top level directory, and all its subdirectories make up the directory hierarchy. This differs to other operating systems such as MS-Windows which applies a separate hierarchy for each device and partition.

As you may have noticed, Linux organizes its files differently from Windows. First the directory structure may seem unlogical and strange and you have no idea where all the programs, icons, config files, and others are. This tuXfile will take you to a guided tour through the Linux file system. This is by no means a complete list of all the directories on Linux, but it shows you the most interesting places in your file system.

The Linux directory hierarchy at a glance The following directories are contained within the structure: Top level directory /

< / >

The root directory. The starting point of your directory structure. This is where the Linux system begins. Every other file and directory on your system is under the root directory. Usually the root directory contains only subdirectories, so it's a bad idea to store single files directly under root.

Don't confuse the root directory with the root user account, root password (which obviously is the root user's password) or root user's home directory.

LINUX systems are divided into hundreds of small packages, each performing some logical group of operations. On LINUX, many small, self-contained packages interoperate to give greater functionality than would large, aggregated pieces of software. There is also no clear distinction between what is part of the operating system and what is an application–every function is just a package.

A software package on a RedHat type system is distributed in a single RedHat Package Manager (RPM) file that has a .rpm extension. On a Debian distribution, the equivalent is a .deb package file, and on the Slackware distribution there are Slackware .tgz files. Each package will unpack as many files, which are placed all over the system. Packages generally do not create major directories but unpack files into existing, well-known, major directories. Note that on a newly installed system there are no files anywhere that do not belong to some package.

RPM packages install usually in /bin /sbin /usr/bin or /usr/sbin Compiled packages usually install in /usr/local/bin or /usr/local/sbin Packages coming form the Unix domain like applixware or Oracle sometimes install in /opt Typically, most of the system is under /usr. This directory can be read-only, since packages should never need to write to this directory–any writing is done under /var or /tmp ( /usr/var and /usr/tmp are often just symlinked to /var or /tmp, respectively). The small amount under / that is not part of another superstructure (usually about 40 megabytes) performs essential system administration functions. These are commands needed to bring up or repair the system in the absence of /usr. The list of superstructure subdirectories and their descriptions is as follows:

Note that the etc directory differs from that of a RedHat distribution. The system startup files /etc/rc.d are greatly simplified under Slackware. The init.d is different for Suse. The /lib/modules/2.6.12-12mdk/ directory contains kernel modules. There can be multiple versions of kernels so the directores are in /lib/modules. Subdirectories bin sbin lib usr var boot dev etc home mnt proc root tmp lost+found opt The Linux Filesystem Hierarchy Listed below are the directories contained within the root filesystem. / The Linux filesystem has the root directory at the top of the directory tree. The following list of directories are subdirectories of the root directory. This directory is denoted by the / (pronounced “slash”) symbol. To view the list of directories from the root directory, enter the following in the command line: $ls / You will see a list of subdirectories output to the screen. All these directories are explained below. One of the best ways to come to terms with a new operating system is to get familiar with the way that the system organizes its files. Files are usually stored in directories which are arranged in a hierarchal tree structure. This is commonly called the directory structure. Here is an example of a common Linux directory structure represented by the KDE desktop. This should look similar to what you would see with most other visual operating systems. Linux uses “The Filesystem Hierarchy Standard”. There will be slight variations but a lot of what you see here is common to many Unix-based systems. Most Linux distributions such as Red Hat, Mandrake, Suse, Debian, etc, use this file system, or at least something very close to it. It should be noted, you can build your own Linux system any way that you want (Free software by definition). There is no strict requirement that you use any particular structure, however, other users will have difficulty using your system and it could turn into a maintenance nightmare very quickly. Some of the directories shown here will be of little interest to many Linux users. For most users, other then root, their primary concern will be their home directory which can be structured any way that is convenient. Windows users will notice that there are no hard drive distinctions. The directory structure shown actually represents a system which has 3 hard drives. With Unix-based systems, drives are not shown. File systems are mounted to particular drives but for the user, the actual implementation is transparent. This approach allows files to be presented to the user in a more centralized view even though the files may actually be spread out among several hard drives and partitions. The result is better security and protection against system crashes and data loss. “/” This is a mandatory directory. It is the beginning of the filesystem and includes all of the directories beneath it. If you type cd / and then ls you will see a listing of all directories on the system (That you have permission to see). This should be similar to the graphic above. /bin This is a mandatory directory. This directory contains the binaries that are used in single-user systems. For multi-user systems these binaries are usually stored in the /usr/bin directory. When you type a command such as ls or chmod it is usually directed to one of these two directories where the program exists.

/bin

These two directories contain a lot of programs (binaries, hence the directory's name) for the system. The /bin directory contains the most important programs that the system needs to operate, such as the shells, ls, grep, and other essential things. /usr/bin in turn contains applications for the system's users. However, in some cases it really doesn't make much difference if you put the program in /bin or /usr/bin.

Binary executables. Usually all bin directories are in the PATH environment variable so that the shell will search all these directories for binaries.

/bin Contains executable programs such as ls and cp. These programs are designed to make the system usable. Programs within /bin are required for system repairing. Some of the files located in the /bin directory include: Shell programs bash sh File manipulation programs tar echo vi grep Process handling programs kill ps

/boot

As the name suggests, this is the place where Linux keeps information that it needs when booting up. For example, this is where the Linux kernel is kept. If you list the contents of /boot, you'll see a file called vmlinuz - that's the kernel. Stored in this directory are files that are required for the Linux boot process. Such files include vmlinuz, the Linux kernel file. This is a mandatory directory. This directory stores the files which are used for the system startup except for the configuration and map installer. Frequently the kernel is stored here especially if more then one kernel is installed.

/dev

This is a mandatory directory. The device files, sockets, and named pipes are stored here. Contains device files required for interfacing with hardware. Devices in UNIX are either block or character devices. Examples of character devices are your keyboard, mouse and serial port. Block devices can include the floppy drive, CD-ROM drive and hard disk. Common files in /dev include: psaux (interface to PS/2 mouse) modem (interface to modem hardware) ttyS0 (first serial port) tty0 (first virtual console). The devices that are available to a Linux system. Remember that in Linux, devices are treated like files and you can read and write devices like they were files. For example, /dev/fd0 is your first floppy drive, /dev/cdrom is your CD drive, /dev/hda is the first IDE hard drive, and so on. All the devices that a Linux kernel can understand are located under /dev, and that's why it contains hundreds of entries.

/etc

  Et cetera. Configuration files. 

This is a mandatory directory. This directory, pronounced “et-see”, holds the configuration files for the system. It is divided into many subdirectories. Contains configuration files which are local to the machine. Programs store configuration files in this directory and these files are referenced when programs are run. Common files or directories found in /etc include: /etc/X11/ (the X Window configuration directory) profile (system-wide environment configuration file). The configuration files for the Linux system. Most of these files are text files and can be edited by hand. Some interesting stuff in this directory: /etc/inittab A text file that describes what processes are started at system bootup and during normal operation. For example, here you can determine if you want the X Window System to start automatically at bootup, and configure what happens when a user presses Ctrl+Alt+Del. /etc/fstab This file contains descriptive information about the various file systems and their mount points, like floppies, cdroms, and so on. /etc/passwd A file that contains various pieces of information for each user account. This is where the users are defined.

/home

This is where users keep their personal files. Every user has their own directory under /home, and usually it's the only place where normal users are allowed to write files. You can configure a Linux system so that normal users can't even list the contents of other users' home directories. This means that if your family members have their own user accounts on your Linux system, they won't see all the w4r3z you keep in your home directory. ;-) This is an optional but widely used directory. The other variation on the /home directory is to use a subdirectory in the /var directory. This is where users will do most of their work. Each user is given their own directory in the /home directory which is theirs to organize and use as they choose. Frequently web server document roots are located in the /home directory. (ex. /home/public_html or /home/www/public_html) The /home directory is designed to host dynamically changing files and usually occupies one of the larger partitions on a hard disk.

Contains user account directories. Each user created by the system administrator will have a subdirectory under /home with the name of the account. This is the default behaviour of Linux systems. E.g. User account for Anna is created, her home directory will be located in /home/anna. All her personal files will reside in this directory. All participants in this class are using the home directories of their respective user accounts. At Computerbank, /home is served via the network, enabling users to access their home directory from any networked machine.

/lib

  Libraries. All other data needed by programs goes in here. Most packages have their own subdirectory under lib to store data files into. Dynamically Linked Libraries (DLLs or .so files.) [Executable program code shared by more than one program in the bin directory to save disk space and memory.] are stored directly in lib. 

This is a mandatory directory. Shared libraries needed at bootup or which need to be run by top level commands are stored here. Libraries which support users are usually stored in the /usr/lib directory.

Contains shared object library files that are necessary to boot the system as well as containing files required by various programs such as rm and ls. This directory also contains modules (located in /lib/modules) which can be loaded into the kernel. Files of interest in /lib include: libm.so (shared object file used for math functions) libc.so (C programming library used for all system and library calls). Module files are located in /lib/modules/`uname -r`/kernel/ The shared libraries for programs that are dynamically linked. The shared libraries are similar to DLL's on Winblows.

/lost+found

Here Linux keeps the files that it restores after a system crash or when a partition hasn't been unmounted before a system shutdown. This way you can recover files that would otherwise have been lost. If you're completely new to Linux, you might want to learn some commands for moving around in the file system, viewing text files, or manipulating the files. In that case I suggest you take a look at the set of tuXfiles in the Introduction to the Linux command line section.

When the filesystem cannot properly identify files, the respective files are placed in this directory. If data appears to have been lost mysteriously, it is a good idea to check in this direetory (or ask your system administrator to check for you).

/mnt

Used for mounting temporary filesystems. When mounting a CD-ROM for instance, the standard mount point location is /mnt/cdrom. This directory is used for mount points. The different physical storage devices (like the hard disk drives, floppies, CD-ROM's) must be attached to some directory in the file system tree before they can be accessed. This attaching is called mounting, and the directory where the device is attached is called the mount point.

The /mnt directory contains mount points for different devices, like /mnt/floppy for the floppy drive, /mnt/cdrom for the CD-ROM, and so on. However, you're not forced to use the /mnt directory for this purpose, you can use whatever directory you wish. Actually in some distros, like Debian and SuSE, the default is to use /floppy and /cdrom as mount points instead of directories under

This is an optional but very popular directory. This directory contains mount points for external storage devices. To access a floppy disk drive you cd to mnt/floppy. Once an external drive is accessed, its file system is mounted to the host system in the /mnt directory.

/opt

This is an optional directory. It is a directory intended to contain software packages which are added to the original system. On my system it is present, but empty.

/proc

This is a special directory. Well, actually /proc is just a virtual directory, because it doesn't exist at all! It contains some info about the kernel itself. There's a bunch of numbered entries that correspond to all processes running on the system, and there are also named entries that permit access to the current configuration of the system. Many of these entries can be viewed.

This is an optional but widely used directory. It contains a virtual filesystem which is created and used by the currently running kernel. It is deleted when the system is shut down. Frequently, monitoring programs use the /proc directory to obtain information on currently running processes and other environmental information.

/root

This is an optional but widely used directory. It is often created to eliminate clutter from the “/” directory. It contains configuration files for the root user. This is the home directory for the super user (root). This directory is not viewable from user accounts. The /root directory usually contains system administration files.

The superuser's (root's) home directory. Don't confuse this with the root directory (/) of a Linux system.

/sbin

Most system administration programs are stored in these directories. In many cases you must run these programs as the root user.

Superuser binary executables. These are programs for system administration only. Only the root will have these executables in their PATH. Similar to /bin, this directory contains executable programs needed to boot the system, however the programs within /sbin are executed by the root user. Contains system maintenance programs, examples of which are: ifconfig (interface configuration, use this command to add or remove a network interface) mkfs (make a filesystem on a partition) lilo (boot loader software, tells your Master Boot Record (MBR) where to find your operating system(s). Linux Loader (LILO) stores its working files in /boot.

/var

  Variable data. Data files that are continually being re-created or updated. 

/usr

This directory contains user applications and a variety of other things for them, like their source codes, and pictures, docs, or config files they use. /usr is the largest directory on a Linux system, and some people like to have it on a separate partition. Some interesting stuff in

/usr:

/usr/doc Documentation for the user apps, in many file formats.

/usr/share Config files and graphics for many user apps.

/usr/src Source code files for the system's software, including the Linux kernel.

/usr/include Header files for the C compiler. The header files define structures and constants that are needed for building most standard programs. A subdirectory under /usr/include contains headers for the C++ compiler.

/usr/X11R6 The X Window System and things for it. The subdirectories under /usr/X11R6 may contain some X binaries themselves, as well as documentation, header files, config files, icons, sounds, and other things related to the graphical programs.

Used to store applications. When installing an application on a Debian GNU/Linux machine, the typical path to install would be /usr/local. You will notice the directory structure within /usr appears similar to the root directory structure. Some directories located within /usr include: /usr/doc - Documentation relating to the installed software programs.

/usr/bin - Executable programs that are not required for booting or repairing the system.

/usr/local/src - Source code for locally installed applications.

/usr/local

This is where you install apps and other files for use on the local machine. If your machine is a part of a network, the /usr directory may physically be on another machine and can be shared by many networked Linux workstations. On this kind of a network, the /usr/local directory contains only stuff that is not supposed to be used on many machines and is intended for use at the local machine only. Most likely your machine isn't a part of a network like this, but it doesn't mean that /usr/local is useless. If you find interesting apps that aren't officially a part of your distro, you should install them in /usr/local. For example, if the app would normally go to /usr/bin but it isn't a part of your distro, you should install it in /usr/local/bin instead. When you keep your own programs away from the programs that are included in your distro, you'll avoid confusion and keep things nice and clean.

/usr/man

  Manual pages. 

/usr/share/info

  Info pages. 

/usr/include

  C header files. These are for development. 

/usr/share

  Shared data. Architecture-independent files. Files that are independent of the hardware platform go here. This allows them to be shared across different machines, even though those machines may have a different kind of processor altogether. 

/usr/share/doc

Documentation. 

/usr/src

  C source files. These are sources to the kernel or locally built packages. 

/tmp

Temporary files. A convenient place for a running program to create a file for temporary use.

This directory is used for temporary storage space. Files within this directory are often cleaned out either at boot time or by a regular job process. The Debian GNU/Linux operating system cleans up the /tmp directory at boot time. An example for using the /tmp directory would be when downloading the OpenOffice deb packages. By downloading these packages into the /tmp directory, the user can be assured the packages will be wiped off the system next time the machine reboots.

/opt

Used for storing random data that has no other logical destination.

/proc

Provides information about running processes and the kernel. A directory is provided for each running process. Useful system information such as the amount of Random Access Memory (RAM) available on the system as well as Central Processing Unit (CPU) speed in Megahertz (MHz) can be found within the /proc directory. The following commands will give you this information:

$ cat /proc/cpuinfo - Display CPU information of system

$ cat /proc/meminfo - Display RAM information as well as swap space capacity and usage.

/sbin

This is a mandatory directory. This directory was originally a place to store static binaries. It has been expanded to include administrative binaries which are used by the root user only.

/tmp

This is a mandatory directory. This directory is used by programs to store temporary files. Files which are located here are often flushed on reboot or flushed periodically.

/usr

This is a mandatory directory. The /usr directory is designed to store static, sharable, read-only data. Programs which are used by all users are frequently stored here. Data which results from these programs is usually stored elsewhere (often /var).

/var

This directory contains files of variable file storage. Files in /var are dynamic and are constantly being written to or changed. Some directories located within

/var includes

/var/spool - files in the print queue

/var/log - files containing logging information

/var/run - files containing the process ID's for each current process.

This is a mandatory directory. This directory stores variable data like logs, mail, and process specific files. Most, but not all, subdirectories and files in the /var directory are shared. This is another popular location for web server document roots. This concludes our whirlwind tour of the Linux “Filesystem Hierarchy Standard”. This standard which has been around since 1993 and provides recommendations which seek to standardize the directory structure of Linux-based systems. Most user accounts will be set up by the administrator so that the user rarely, if ever, has to venture out of their /home/username directory. System administrators are the only ones who really need to be concerned with the other directories.

Hopefully this discussion has clarified the directory structure of Linux and made the system more undersandable. Linux is really no more difficult to understand then any other operating system. This directory contains variable data that changes constantly when the system is running. Some interesting subdirectories:

/var/log A directory that contains system log files. They're updated when the system runs, and checking them out can give you valuable info about the health of your system. If something in your system suddenly goes wrong, the log files may contain some info about the situation.

/var/mail Incoming and outgoing mail is stored in this directory.

/var/spool This directory holds files that are queued for some process, like printing. < /tmp > Programs can write their temporary files here.

References :

Rute book Chapter 17 http://rute.2038bug.com/node20.html.gz

http://doc.vic.computerbank.org.au/tutorials/linuxdirectorystructure/

Filesystem Hierarchy Standard (FHS) http://www.pathname.com/fhs/

http://www.dynamic-apps.com/linux_directories.jsp

http://www.tuxfiles.org/linuxhelp/linuxdir.html

products/ict/linux/directory_structure.txt · Last modified: 2024/04/25 10:28 by wikiadmin