User Tools

Site Tools


products:ict:linux:directory_structure

This is an old revision of the document!


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.1650964723.txt.gz · Last modified: 2022/04/26 14:18 by 127.0.0.1