The Linux Filesystem

Govind Menon
3 min readMar 11, 2021

Imagine a system where once you store data, you do not know where it is or how it is stored!

Scary isn’t it?

File systems have been designed by OS manufacturers to tackle this very issue: store and retrieve data in a predictable and organised method. In lieu of keeping each story short and crisp, I have divided it into multiple stories:

  1. Filesystem Hierarchy Standard (FHS)
  2. Linux Filetypes
  3. What is an inode?
  4. Journaling in a File System
  5. EXTended File System (EXT) Introduction
  6. EXTended File System (EXT) Allocation Primer
  7. eXtents File System (XFS) Introduction
Representative image for a Linux based OS

Filesystem Hierarchy Standard

The linux filesystem in theory is based on the Filesystem Hierarchy Standard or FHS but the different distributions (Debian, Redhat, among others) tweak the same to meet their design or performance or usage specifications. FHS describes the directory structure and its content in Unix and Unix like operating systems. It explains where files and directories should be located and what it should contain. Its current version is 3.0 and is maintained by the Free Standards Group. In Linux, everything is considered a file. The below command describes the filesystem hierarchy used in your system:

man hier
Types of hierarchies that exist in FHS

Note: If viewing on the medium app, please click on view larger version for the best experience.

Root

/ is the root of the filesystem — parent of every other file in linux.

Interesting fact: If you are a root user, never run rm -rf /.

Binary

Binary files are the files which contain compiled source code (or machine code). They are analogous to executables on a windows system. Four types of binary layouts exist in linux:

  1. /bin
  2. /sbin
  3. /lib
  4. /opt

Note: Please wait for the below sway to load for more information on the above layouts.

A sway for binary that describes the above layouts in slight depth

Configuration

Configuration files contain initial settings and parameters for programs and the operating system itself. Two major layouts exist:

  1. /boot
  2. /etc

Note: Please wait for the below sway to load for more information on the above layouts.

A sway for configuration that describes the above layouts in more depth

Unix System Resource

It is also called secondary hierarchy as it contains binaries, libraries, documentation — shareable and read-only for all the user applications.

The /usr layout comes under this classification. It is called a secondary filesystem as it mirrors the primary one anchored at / and has similar subdirectories such as bin, sbin. It has the following subdirectories in order:

  • /usr/bin non-essential binary commands for all users
  • /usr/include header files for C
  • /usr/lib contains libraries used by /usr/bin and /usr/sbin
  • /usr/share architecture independent data is stored here. Example can be documentation, manuals, etc. that can be shared across network systems
  • /usr/src contains source code files, such as the kernel source code with header files

Variable Sized

Contains files that may continuously change size such as spool files (for printer and email buffers), log files and cache files.

The /var layout comes under this classification which can further have the following subdirectories:

  • /var/log contains all log files
  • /var/cache cache generated due to I/O by applications such as apt
  • /var/spool contains files waiting to be processed — printing and mails
  • /var/lib state files such as databases

Memory

The filesystem layouts that do not take up any actual disk space are classified here. Three major classifications can be made:

  1. /dev
  2. /proc
  3. /sys

Note: Please wait for the below sway to load for more information on the above layouts.

A sway for memory that describes the above layouts in more depth

Data

The only portion that most linux users interact with on a daily basis is the Data classification. The following layouts exist within the same:

  1. /home
  2. /root
  3. /media
  4. /mnt
  5. /srv
  6. /tmp

Note: Please wait for the below sway to load for more information on the above layouts.

A sway for data that describes the above layouts in more depth

Extra resources one can refer to:

https://www.javatpoint.com/linux-file-hierarchy-system

With this we complete the first section of the Linux Filesystem. You can find the next section here.

--

--