File System of Linux

Linux file system follows a tree-like hierarchical structure starting at the root. It consists of directories, sub-directories, and data files. This structure follows a standard layout recommended by Filesystem Hierarchy Standard (FHS), which is a standard maintained by the Linux Foundation.
Below, I provide a picture of a tree-like structure of the root directory.

Before moving forward, I want to emphasize a point that is unique to Unix-like systems. These systems intend to keep things simple and treat every thing as a sequence of bytes. These sequence of bytes are known as files to the OS. So, in that sense, everything is a file. Even your hardware devices are files. Your printer is a file, your memory is a file, basically everything. This approach has allowed these systems to become extremely flexible. Since I believe the internal workings of Linux directories has some merits to learn, I have created a section at the end of this tutorial to explain it in detail. However, for now, I skip this topic because you might get sidetracked.
Unlike Windows which has multiple roots, the Linux only allows one root. Below, you can see a picture of standard folders on the root directory. The root directory is where all other directories and files on the system reside and is designated by a forward slash /
.
Here, in this tutorial, I try to explain each directory and provide some useful information about each one of them. I try to explain them in the order of importance and relevance.

/home directory
home directory, a.k.a login directory, is where every user stores their personal files and documents. Linux is a multi-user environment so each user is assigned a specific directory that is accessible only to them and the system administrator.
The home directory contains your personal configuration files, the so-called leading dot files. These files are usually hidden, and you need ls
with -a
option to view them. If there is a conflict between personal and system-wide configuration files, the settings in the personal files have priority.
This directly can grow very large as you store your files, downloads, applications, videos, pictures and sounds.
Keep in mind that this directory is the only directory that you can write on without the privileged access of root user. For the other directories, although you can read most of them without root access, you can’t modify and write on them.


/bin and /sbin directories
bin is short for binary. This is where Linux keeps its basic programs and applications. Binary files are the executable files that contain compiled source code. Almost all basic Linux commands can be found here such ls
, cat
, touch
, pwd
, rm
, echo
, … The binaries on this directory must be available in order to attain minimal functionality for the purposes of booting and repairing a system.

sbin is short for system binary. Similar to bin, it is also a place for storing executable programs. But these executable programs are essential for system configuration, maintenance and administrative tasks. Linux has decided to discriminate between normal binaries and these system binaries. In other words, this directory is reserved for programs essential for booting, restoring and recovering. For example, look at some examples of sbin binaries, fsck
, a filesystem check and repair utility, or reboot
, restart the system.
Because of the need for privileged access, the directory is not part of default $PATH
environmental variables. $PATH
contains the paths where ordinary users search to look up their binaries and there is no need for root access to search these paths.

/usr directory
usr stands for Unix System Resources. It belongs to the user applications as opposed to /bin
or /sbin
directories which belong to system applications. Any application installed here is considered nonessential for basic system operation. However, this is one of the most important directories in the system as it contains all the user-level binaries, their documentation, libraries, header files, etc. This directory is read-only and applications should not write anything into it.
/usr
subdirectories:
/usr/bin
contains the vast majority of binaries on your system. Binaries in this directory have a wide range of applications. For example,vi
,firefox
,atom
,gcc
,curl
,dpkg
, … are all here./usr/sbin
contains programs for administrative tasks. They need privileged access. Similar to/sbin
, they are not part of$PATH
./usr/lib
contains program libraries. Libraries are collections of frequently used program routines./usr/local
contains self-compiled or third-party programs. This directory is similar in structure to the parent/usr/
directory and is recommended to be used by the system administrator when installing software locally./usr/src
contains kernel sources, header-files and documentation./usr/include
contains all header files necessary for compiling user space source code./usr/share
contains shareable, architecture-independent files (e.g. docs, icons, fonts, etc). It is recommended that any program which contains or requires data that doesn’t need to be modified store them in this sub-directory (or/usr/local/share
, if installed locally).
Trivia: Originally this directory was intended to be anything user-related, but over time, it lost its significance and now it is a place for “user usable programs and data”.

/etc directory
This is where all your system-wide configurations are stored. So, if you have a system-wide application on your Linux, you can find its configuration files here.
Look at the below picture, it is a view inside the /etc directory. all dark blue names are directories and inside each one is a configuration file. For example, configurations for python
, python3
, perl
, ssh
, apt
, firefox
, emacs
, …


/opt directory
opt stands for optional. This is where manually installed software reside. For example, in below example, you can see software folders for zoom
, BlueJeans
, containerd
, skypeforlinux
, and google
(Google chrome) which are softwares installed on my computer.

/snap directory
This directory is where your snap packages are stored. Snap packages are self-contained packages that don’t depend on any other packages, dependencies, or libraries.
The differences between a snap package and regular Deb package are as follows:
- After installation, their pieces do not spread on various directories. They will be all contained in a folder on
/snap
directory. - They do not depend on any other packages, dependencies, or libraries. They are bundled with everything they need for proper functioning.
- They are completely isolated from the rest of the system. So, they doesn’t mess up with other files.
Below, I shared a view inside my /snap
directory. These are all snap packages. For example, let’s dig deeper inside the telegram-desktop
snap package. A view inside this snap package is shared below. As you see, it is a self-contained package and has all necessary libraries and dependencies for proper functioning.


/lib /lib32 /lib64 directories
lib stands for library. These are library files directories. These library files are programs that are shared among other binary applications. Binary files inside bin and sbin use these library files extensively. If you want to know which command uses which library files, you can trace them using strace
command. For example, let’s see what library files ls
command uses.
$ strace -e open ls
The answer is shown in the below picture. As you see, ls
command needs almost all library files inside /lib directory to function properly.

/var directory
var stands for variables. This directory contains variable data like system logging files, mail and printer spool directories, and transient and temporary files. These are typically file and directories that are expected to grow in size. For example, /var/crash
holds information about every time a process has crashed. Or /var/log
has all log files for your computer and its applications, which grow constantly with time.


/media directory
This is where your OS automatically mount your external removable devices such USB thumb drive.
/mnt directory
This is where you can mount external devices manually. It can be floppy disk, external hard drives, network drive, etc.
/media and /mnt are basically the same; however, it is recommended to use /mnt for manual mounting and leave media directory for the OS.
/boot directory
This is where your boot loader lives. It contains the static bootloader, kernel executable and configuration files required to boot a computer.

/sys directory
This is where you can interact with the kernel. In other words, you can consider it as an interface to the kernel. This directory is a virtual filesystem, which means the files live on memory and disappear after shutdown. In essence /sys
allows you to get information about the system and its components in a structured way.

/dev directory
This is where your device (a.k.a special) files reside. These files allow application programs to interact with your hardware devices. Keep in mind that these are not device drivers, rather they are files that represent each device on the computer and facilitate access to those devices.
These special files can either be character or block files. A block device is any device which performs data I/O in units of blocks, e.g. hard disk, whereas character device is any device which performs data I/O in units of character such as standard input/output (keyboard/screen).
Below, I have provided a few examples of device files.
- first hard disk:
/dev/sda
(its first partition is/dev/sda1
) - printer:
/dev/lp0
- Computer memory:
/dev/mem
- A terminal (keyboard or screen):
/dev/tty
/sys
and /dev
are both related to devices, so they might be confusing. However, they are very different. /sys
directory has files that provide information about devices. Information such as whether they are powered on, their vendor name, model, etc. On the other hand, /dev
directory has files that allow programs to access the devices (write data to a serial port, read a hard disk, etc). As you see, they are very different.

/proc directory
proc stands for process. On this directory, you can find pseudo-files containing information about system processes and resources. For example, every process on your computer would have a folder with information about that process on this directory. This directory is a virtual filesystem and disappears once the the computer is shut down.
As an example, let’s see folders inside this directory. I first look at the running process on my computer with htop
command. I sorted these running process based on their uptime. Let’s pick the first 3 processes, their PID (Process ID) are 1916, 28233, and 28197. Let’s look at inside the proc directory. As you can see, each one of them has a folder inside proc directory which contains the necessary parameters for each process.
Another example is information about resources such as CPU (on /dev/cpuinfo
) or uptime (on /dev/uptime
).


/run directory
Modern Linux distributions have included this directory as a temporary filesystem (tmpfs) which stores RAM runtime data. That means that daemons like systemd
and udev
, which are started very early in the boot process (and perhaps before /var/run
was available) have a standardized filesystem location available where they can store runtime information. Since files on this directory are stored on RAM,they disappear after shutdown.
/run/udev
is a device manager for the Linux kernel, and /run/systemd
is a suite of basic building blocks that provide a standard process for controlling what programs run when the system boots up.

/tmp directory
This is where applications store the temporary files they need during a session. For example, when you are writing a word document in a word processor, it stores a temporary file saving all you write. If for some reason your system crashes before saving the file, the word processor can search this directory to find a recent saved copy to recover your text. This directory is usually empty when you reboot your system.

/root directory
This is a directory for superuser (i.e. administrator). You can look at it as a root user’s home directory. It is only accessible to superuser. On my computer, it is an empty folder. However, it is reserved for configuration files for the root account.
/srv directory
It is a service directory. If you are running a web server, you can store site-specific data on this folder.
/cdrom directory
This is a legacy directory to mount CD-ROM. However, today CD-ROMs are automatically mounted on media directory.
Blog Created by:
TY CS A Group N0. 14