Understanding Linux Directory Structure

Hello People! When you people have switched from windows to linux you might’ve thought that why everything in the file manager is showing as a folder other than a disk or something like in windows right? That is because everything in Unix or Linux file system is considered as a file even if it is a physical device such as Cd-Rom, Pen Drive, External HDD etc…

The file system in linux is like a tree with a root */* and other directories like branches. The thing here is root is at the top of the tree. Each file or directory in linux is identified with an inode.

The default directories in unix/linux file systems generally have there specific purposes and hold the same kind of information in them for easily locating them.Let’s dig into the default directories of a linux based operating system.

/ : “/” or root is the base directory of linux system. which contains all those files/folders which are needed for an operating system to run. all your files, hard drives, mounted dvd/cd-roms, pen drives everything is stored/located in the root.See the image to know how / directory looks :

root meaning linux


Here all the required executables and binaries are stored which are necessary for the operating system to boot and run.Nothing in this folder is stored as a text file it contains files which are ready to get executed.This folder is available to every user created on the system.You can see how it looks like in below image.

bin linux file system


As the name itself says for what this folder is needed. It is needed on your system to boot. It contains linux kernel, disk image of RAM for some drivers which needed at the time of boot and bootloader (i.e : grub). Below is the screenshot of /boot directory.

boot directory linux


Here in this folder you can find all the mounted devices like your hdd, usb etc. All these devices are represented as files.It not only contains the devices which are mounted but also contains devices which are connected to the system but aren’t mounted.You can see how it looks in the image below.

dev folder linux


You can find all the configuration files of the system, shell scripts, user list, hosts, groups and many other things. All the files in /etc are text files so they are human readable.
For example : /etc/passwd this passwd file contains all users and there information.

etc file system


This contains data of users on the system like pictures, downloaded files, documents, videos, music etc. if you have more than 1 user on your system you can see different folders of those different users in /home directory. In below images you will see home directory showing username folder (1st) & home directory of the user (2nd).

home vs rootroot vs home


This /lib stands for libraries which is a set of functions required by some programs. In linux this folder contains libraries required for programs in /bin directory.Below is the image of lib directory.

linux file system


This directory is used for automatic mounting of removable devices like external harddisk, USB, CD/DVD etc. Below is the screenshot of /media directory.

media directory linux


This is similar to /media and is used for mounting as well but it is used for manual mounting devices. It can stay empty, although you can create subdirectories to it for mounting individual devices.Below is the image of /mnt directory, I haven’t inserted any external device so it’s empty.

what is /mnt


This directory is reserved for the optional softwares or programs which are not part of default system installation. It is not that essential for your system like if it mistakenly gets deleted it won’t effect on the system just some third-party programs installed by you will be lost. You can check out the image below to see how it looks like.

what is /opt


This is very special directory on the system as it is also a virtual file system maintained by Linux Kernel. It contains runtime information about the system.

Example : System Memory, Hardware Configs, mounted devices. A normal user on the system cannot touch any file in this directory. It is basically needed for the kernel to run different processes on the system.

./proc in linux


It is also a home directory like /home but for the root user of the system. Do not get confused between /root and / both have difference /root contains the same kind of information which /home directory holds. / is the parent directory of the whole linux system also known as root. If you login to your system as a root user or just type “sudo su” in your terminal you will be located into this /root directory by default. Simply, it’s the best place in your system to hide porn or girlfriend’s photos lol. *Just kidding* Below image shows how it looks.

/root in linux


It is newly introduced directory on the file system. It is actually a temp folder for things like systemd and udev to run on boot time. It is a replacement of /var/run.Below is how it looks.

run directory


It similar to /bin also contains binaries essential for system tasks. But is meant to run by the Super user A.K.A ROOT. This is where you find your network daemons with other binaries which only a system administrator has access to. Binaries in here are not required for system maintenance or repair.

bin vs sbin linux


It is a serve folder which holds service files installed on your system. like you install web server on your system it will be located in /srv directory.Below is the image of /srv directory.

srv directory


This holds temporary files of programs running on your system.I suggest not to delete files in /tmp manually as it may contain some useful files required for some programs currently running on your system you can add this removing procedure to bootup or shutdown procedure. Below is how /tmp looks.

tmp directory linux


This is the largest directory on the file system as it holds binaries and libraries and header files for all programs which a regular user uses on the system. It contains shared data of users like themes, configuration files, sounds, wallpapers, icons etc. Below image is of /usr directory.

usr folder linux


This directory contains files which change all the time while system runs like log files, cache, backups etc. Below is how it looks.

var linux


This is the recovery folder for the system. if you ever have a system crash and Linux file system checker *fsck* recovers corrupt files they are placed in this. Every partition on the file system has it’s own Lost+Found. Below image shows how a lost+found looks like.

lost and found linux

Well thats all! I hope you learned something new from this article.

I will be writing more articles in this Linux Basics series so we will catch up in next article. Till then, Keep learning! Keep Hacking!

Also Read: Basic Linux Terms

About the author


A Noob Hacker learning to become leet xD, a Proud member and an admin at Ultimate Hackers.


Click here to post a comment

Subscribe Now

Subscribe for free and get latest articles delivered right into your inbox.

Thank you for subscribing.

Something went wrong.