[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Understanding Linux Directories and Files

Files serve to store data permanently. Files are normally organized in a tree-like hierarchy where intermediate nodes are directories, which in turn are capable of grouping files and sub-directories.

3.1 /: The root directory  
3.2 The Directory Structure  
3.3 /dev:The Directory to Devices  
3.4 /proc: The Directory of Processes  
3.5 More Information on Linux Directory  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 /: The root directory

The root of the directory tree is /. This directory should contain no files ( only directories) or very few files, such as the kernel image.

In the root directory you will find the following subdirectories.
*Note* Depending on the distribution you are using, you may or may not have all of the following directories.

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

Once you have a basic understanding of the GNU/Linux directory structure, it is easy to find and modify any file you wish.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 The Directory Structure

The /bin directory has basic executables for commands, such as ls, sync, cat.The /bin directory holds programs that make the system usable, but aren't absolutely necessary to have to keep the system running.

The next directory is /boot. Not all distributions have this directory. If present, it usually contains kernels and boot maps for booting.

Next is the /dev directory, which is an interface to the devices attached to the computer. The files in /dev are not actually drivers. For more information, see 3.3 /dev:The Directory to Devices.

Next is the directory /etc. /etc holds the configuration files for most applications. All manner of systems configuration files go in /etc.

Next is the directory /home/user. The files created by the users of their own that they need to store are usually stored in /home/user. Each user has a user name and a directory in /home with that user name to use as their home directory. They can place any kind of files there, and set up permissions to allow exactly whom they wish to see their data.

The next directory is /lib.The /lib directory contains shared object libraries that are needed by programs,which make system and library calls. The directories /usr/X11R6/lib, /usr/lib and /usr/local/lib are other repositories of libraries.

Next is the directory /lost+found. Files can be lost due to improper shutdown. The /lost+found directory is used for any pieces of files that can't be identified when the file system is cleaned up. If you lose some data mysteriously, check here.

/mnt is a mount point for temporarily mounted file systems. Usually to use floppy and CD-ROM drives, they are mounted in the /mnt directory. Some distributions use /cdrom for CD-ROMs and /mnt for floppies, while still others use /mnt/cdrom for CD-ROMs and /mnt/floppy for floppies.

Next is /proc. /proc is used as an interface to kernel data structure. For more information, see 3.4 /proc: The Directory of Processes.

The /root directory is the home directory of root (the system administrator). Often, in /root, you will find programs or scripts written by root that perform some task for the machine.

The /sbin directory contains binaries that normal users generally don't need-- binaries meant for root. Other sbin directories are /usr/sbin, /usr/local/sbin.

The /tmp directory is used as scratch space. If you are decompressing an application but the combined size of the zip file and the untarred data is too large for your /home, use can use /tmp for temporarily storing the zip file.The /tmp directory is meant to be used as storage space. It is usually deleted often to keep the system clean, so you shouldn't leave files laying around in there.

/usr contains many files for users (as the name implies) and their programs. It has sub directories similar to those in the root directory, i.e. /usr/lib,/usr/bin etc. /usr/src has the source code for apps and the Linux kernel resides here.

Finally, there is the /var directory. As the name implies it is used to store variable files (in size or time or content). It is used to store temporary material, like files waiting to be printed or mail waiting to be read, and you don't know how long you will need to store them (so /tmp isn't an option). /var/tmp can be used to store temporary information here instead of in /tmp. The advantage is that /var/tmp doesn't get deleted regularly.

With an understanding of where files are located in GNU/Linux, system maintenance becomes easier.

However, the two directories, /proc and /dev are not at first glance easily understandable. They are, however, powerful tools for understanding and using GNU/Linux. I have covered them separately.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 /dev:The Directory to Devices

There are two categories of devices: character devices and block devices. Character devices deal with the input/output on a character by character basis. The most obvious example is a keyboard, where every key generates a character on the device. The mouse is another. Every motion or button click generates a character input for the computer to deal with.

Block devices read data in larger chunks. Data storage devices, such as IDE hard drives, SCSI hard drives, and CD- ROMs are block devices. Input/output interactions with block devices transact with chunks of data, which allows large quantities of data to be moved back and forth more efficiently.

Devices are often named after the equipment they represent. For example, devices name /dev/hd* represent IDE hard disks (hd).

In some cases, there may be multiple devices of the same type. For instance, a machine may have two ATAPI CD-ROMS. Two devices will be used -- one for each device. For instance, /dev/cdrom0 will be the first CD-ROM, and /dev/cdrom1 will be the second.

A hard disk device name is composed of the type of disk followed by the position of the disk, and then the disk partition. The first hard disk may be called /dev/hda, with the "hd" part indicating that it is an IDE hard disk, and the "a" part indicating that it is the first hard disk. /dev/hdb would then refer to the second hard disk. Each hard disk is divided into partitions. The first partition on the first hard drive would be /dev/hda1, where the "1" at the end indicates the location of the partition.

SCSI hard disks use /dev/sd instead of /dev/hd, but otherwise the convention is the same.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 /proc: The Directory of Processes

At any given time, Linux will have many processes running at once. Some, such as window managers, email clients, and web browsers, will be visible to the end user. Others, like servers and helper processes, are not immediately visible, but run in the background, handling tasks that do not require the users' interaction in order to manage the system, the kernel must keep track of every process running, including itself. Many user-level applications, too, must be able to find out what processes are running .The /proc file system is where the kernel stores information about processes. /proc is controlled by the kernel and does not have an underlying device. In addition to storing information about specific processes, the /proc file system contains a great deal of information generated by the kernel itself to describe the state of the system.

The kernel and its modules may generate files in /proc to provide information about their current state.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5 More Information on Linux Directory

Start any terminal emulator. At the command prompt type man hier. It has a detailed explanation on the hierarchy of the Linux directory structure. When you press q, you will exit from the man page
In a terminal emulator, type man proc 5. This will give you a very detailed explanation of the files and directories found in the /proc directory. To exit the man page type q.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated on March, 5 2003 using texi2html
Hosted by www.Geocities.ws

1