The Linux Filesystem
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:
- Filesystem Hierarchy Standard (FHS)
- Linux Filetypes
- What is an inode?
- Journaling in a File System
- EXTended File System (EXT) Introduction
- EXTended File System (EXT) Allocation Primer
- eXtents File System (XFS) Introduction
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
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:
/bin
/sbin
/lib
/opt
Note: Please wait for the below sway to load for more information on the above layouts.
Configuration
Configuration files contain initial settings and parameters for programs and the operating system itself. Two major layouts exist:
/boot
/etc
Note: Please wait for the below sway to load for more information on the above layouts.
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 asapt
/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:
/dev
/proc
/sys
Note: Please wait for the below sway to load for more information on the above layouts.
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:
/home
/root
/media
/mnt
/srv
/tmp
Note: Please wait for the below sway to load for more information on the above layouts.
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.