Linux directory structure

From GluCki
Jump to: navigation, search

In Windows, most of us are familiar with filesystem structure and the directories with their role. 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.

Lets go into the filesystem and directory structure and throw some light on each directory and its use

/

The Root
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 sub directories, so it’s a bad idea to store single files directly under root.

boot

Boot Loader Files
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.

bin

Binaries or Programs
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

System Binaries
Most system administration programs are stored in these directories. In many cases you must run these 
programs as the root user. e.g. ifconfig, poweroff, restart </p>

etc

Configuration Files
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:

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.

fstab

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

usr

User Binaries 
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:

doc

Documentation for the user apps, in many file formats.

share

Config files and graphics for many user apps.

src

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

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.

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

Library (Shared and System)
The shared libraries for programs that are dynamically linked. The shared libraries are similar to DLL's on Winblows

media

Removable Media Devices
The temporary mount directory for removable devices.
For example, /media/cdrom for CD-ROM, /media/cdrecorder for CD writer

mnt

Mount Directory 
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.


opt

Optional Addon Applications
The /opt directory contains add-on applications from individual vendors.
Add-on applications should be installed under either /opt/ or /opt/ sub-directory.


proc

Process Information
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.

var

Variable Files
This directory contains variable data that changes constantly when the system is running.
For sample, /var/log, /var/spool, /var/mail.

tmp

Temporary Directory
The /tmp directory must be made available for programs that require temporary files.
Files under this directory are deleted when system is rebooted.

dev

Device Files
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.

home

Home Directories
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. For examples, /home/vishant , /home/nemo