Linux Directory Structure

Since Linux a File based operating system, Linux directory structure play important role. So before going into much detail about the basic command let us explore Linux Directory Structure.

In this part we will explore the different system created top level directories of the Linux. If you have installed Linux then before moving further you must be aware about Linux Directory Structure. In this chapter I will ask you to run few command to get the directory structure in the Linux at different level. This are very basic command so do not worry (even I we will explore much details of those command in later chapters).

Linux Directory Structure

If you have Linux installed on your PC, then you can see you have different pre-created directories. This directories are created by Linux as per its conventions to put its system created files. Also you can put your own files in these directories. Run the following command on your Linux Machine:
cd /
ls -l

You can see following directories:

Linux Directory Structure
above snapshot has top level directories of the Linux.

Different distributions of Linux has some slightly different directory structure but some important directories like boot, var, etc are some common directory. Above snapshot is directory structure of CentOS 5.5

Further in this tutorial we will discuss uses of each directory in depth.

/bin Directory

Bin directory contains executable of the some useful Linux software or you can say command. Bin directory contains command which is used by administrator and other user. It contains command like CP, MV, LS etc. Command stored in /bin directory can also be used in the single user mode. This directory does not have any other sub directories.

/boot Directory

/boot directory contains the file reqired on booting Linux. It also stores data related to kernel loading. It contains grub loader files also. If you are running Linux on vmware then it contains your VM related booting data also. Following are few sub directories/files of /boot directory:

  1. /boot/grub : Contains file related to grub
  2. /boot/vmlinuz : File related to vm boot
  3. /boot/initrd : Initrd related data.

/dev Directory

This is very important directory of the Linux, but as a general user you never need to know much detail. But if you want to be a Linux developer then this directory is very important for you. This directory contains files releted to devices in Linux. Dev word is taken from device. It contains file related to hard disc, CD ROM, audio , Input devices etc. Following are few example of the files/directory of /dev directory:

  1. /dev/bus : Contains file related to bus.
  2. /dev/audio : Files related to audio.
  3. /dev/ram0 : Data related to RAM.

/etc Directory

/etc directory is brain of your Linux. It contains configuration file related to system and user packages. Configuration files mean the file which control operation of the packages.  Means if you want to run some packages on the login of the user you can define it here.

For example it contains configuration for X11 which is system package and your apache web server which is a user packages. If you have PHP installed then configuration file of PHP i.e. php.ini by default stored here.

/home Directory

Home directory contains directory for Users. This is something similar to window My Document Folder.

Since Linux is one of the big Multi-User Operating system, every user has some dedicated place for this files. So home directory is made to server this purpose. If you will create user in Linux, folder in the home directory will be created for that user. Only administrator and the user(for which sub directories is created) can access the directory.

/lib Directory

/lib directory contains various library which is used by different command on Linux. Lib directory contains some shared library which is used by more than one Linux command. It contains kernel and other c library as well. As in windows operating system you have heard about .DLL files, Linux libraries contains .so extension. If you will go to the /lib directory of the Linux you can get several files with extension .so. .so files of the lib directries are the library files of the Linux.

/media Directory

This directory is mount point for removable media. Media directory is used for removable media. When you insert USB stick or CD then a folder in the media directory will be automatically created for that. You can directory go to that directory and access removable media.

 /mnt Directory

/mnt directory is also use for mount point. But is is used for mounting all devices and file system. Mounting is process by which you can make other device filesystem available to the Linux. Remember windows CD drive and USB, you just insert it and it automatically mounted. Linux also has plug and play features.

Once you will mount a device a sub directory will be created in the /mnt directory. You can go to that sub directory and directly access the file system of that hardware.

/opt Directory

/opt directory is for all optional or additional software. Event you can create your own program and place in opt directory or sometime additional software packages installed form third party also goes in opt directory. Or in other word we can say that all add-on that is not part of default Linux distributional should go in /opt directory.

/proc Directory

Aha! /opt is a very special directory. This directory contains all running process information. If you will create a process by launching any command you can see a file with the same process name exists in proc directory.

Basically /proc does not really stores any process in the folder. All files in the proc directory are virtual.  If you will see the size of the files stored in the /proc directory then you can found that every file size is 0 byte. It is because these files are pointers of the process. You can still get your process information by these file. Please enter following command to your shell

cat /proc/iomem
and you can see all information related to iomem process.

/root Directory

/root directory is home directory of root user or super administrator user. For general user home directory is created under /home/youruser directory. But for root user home directory is /root. The reason behind this change in the Linux is to provide some flexibility  Usually root user has all and every thing privileged. So sometime he mount other user home directory on different partition. So in case that partition will be courputed root user can still login and fix the issue.

/sbin Directory

/sbin directory is identical to /bin directory. It store binary executable. But /sbin directory only store executable used for system maintenance or administrative task. Generally it contains binary executable of booting, backup, restoration etc.

/usr Directory

This is one of the most useful directory in Linux operating system. It contains data like binary, documentation, library etc which could be shared among users. Basically it contains read only data. It never contains any files which will be changed dynamically. This is basically user system resource directory on the Linux file system.

/var directory

This is again one of the most important directory in the Linux. This is opposite of /usr directory. As usr directory contains only read only files, /var directory contains all variables and rightable files. Basically it stores data which is variables and dynamically changed like logs, locks etc.

If you are learning Linux for server and system administration purpose then you will defiantly open this directly almost every day. This directory store backup, db server middle-ware files, if running apache then .html files etc.

/tmp directory

This directory contains temporary files. You can use this directory to store your files temporary. For example suppose you want to download and install a package. So you can download the package in /tmp directory and install it. After installation you can delete. /tmp directory is accessible from all user.

Sometime some running packages of Linux create temporary files in /tmp directory and store data for short terms use. Please do not delete any files from /tmp directory if you are not aware of why it is created. Because deleting files from /tmp directory may crash any user program.


Above is only top level directory structure and expatiation is very brief so that you can atlease get awareness about the filesystem hierarchy of Linux. But if you want to be pro then you have to dig into detail of Linux directory structure. Understanding of Linux directory structure is first   step but most important thing for Linux learner. If you have good understanding of what is where in Linux or in other word Linux Directory strucure then you know atleast more than 50% of Linux.

So I always recomend to dig more about Linux directory structure after finishing  this tutorial series.

For More details about the Linux Directory and Hierarchy you can refer following URL:

Next >> Basic Linux Command

Leave a Reply

Your email address will not be published. Required fields are marked *

seven − six =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>