Exploring Linux File System
After understanding how a filesystem works now I will be covering specifically linux file system and its directory structure, explaining how the data is stored and kept in linux. Linux supports many other filesystems such as ext3 ,
ext4 , btrfs and many more. It supports around 100 types of filesytems and even the old ones but the most common filesystem among linux distributions is
ext4 .
The Directory Structure.
In Linux and its many other distributions, A directory is structured in a tree like hiearchy system. Linux directory structure is well defined and documented in the FHS (File Hiearchy Standard). FHS is maintained by the Linux Foundation and its followed by major linux distributions.
The root / is the top of the filesystem (basically it contains everything that is required or used by the OS).
/ ├── bin -> usr/bin ├── boot ├── dev ├── etc ├── home ├── lib -> usr/lib ├── lib64 -> usr/lib ├── lost+found ├── mnt ├── opt ├── proc ├── root ├── run ├── sbin -> usr/bin ├── snap -> /var/lib/snapd/snap ├── srv ├── sys ├── tmp ├── usr └── var 20 directories, 0 files
As you can see how root directory represented using ( / ) contains everything.
Note: You can also think of directory as file that holds bunch of addresses to other files.
I will be covering each directory separately explaining what each directory holds and represents.
bin/
This directory is called binaries as this holds all the programs that live in our machine. For example here’s what a bin/ directory might look like and it mostly contains executables .
➜ ~ tree -L 1 /bin -C | tail -n 20 ├── znew ├── zonetab2pot.py ├── zoom -> /opt/zoom/ZoomLauncher ├── zramctl ├── zresample ├── zretune ├── zsh ├── zsh-5.8 ├── zsoelim -> soelim ├── zstd ├── zstdcat -> zstd ├── zstdgrep ├── zstdless ├── zstdmt -> /usr/bin/zstd ├── zvbi-atsc-cc ├── zvbi-chains ├── zvbid └── zvbi-ntsc-cc
boot/
This directory contains all the files required by the kernel at the time of boot and our bootloader also resides in this directory.
/boot ├── grub ├── initramfs-linux-fallback.img ├── initramfs-linux.img ├── initramfs-linux-lts-fallback.img ├── initramfs-linux-lts.img ├── intel-ucode.img ├── lost+found ├── vmlinuz-linux └── vmlinuz-linux-lts
As you can see grub is also present in the boot/ directory
sbin/
This directory contains the system binaries that are required for the system adminstration.
dev/
This directory contains all the devices and each device is represented with a file. This only represents devices attached to the system. For example your disk might show up as dev/sda and partition might show up as dev/sda1 . This folder is usually accesed by the drivers and applications.
etc/
This directory is known as edit to configure but it was also known as
et cetera as you can read here more about the history of
etc/ directory name.
etc/ directory is where all your configs are stored for software used by the system. For example ,package manager such as pacman or apt as etc/ holds the config of your package manager.
➜ ~ tree -L 1 /etc | grep "pacman" ├── pacman.conf
lib/
This directory is also known as libraries and it contains all the libraries that are required to boot the system and used by different applications to perform different functions.
media & mnt/
This directory contains the mounted drives. For example this is where you will find an another mounted drive such as External HDD or SSD . If you are mounting things manually use the mnt/ directory and media/ is where your
OS will automatically mount.
opt/
This drive contains all the manually installed software usually from the vendor.
Note: Some software installed from package manager might also live here
➜ ~ tree -L 1 /opt /opt ├── Simplenote ├── sublime_text_3 └── zoom
For example you can see zoom and sublime text .
proc/
In this directory you will mostly find files which contains the information of the hardware and even the running processes in the system. Each process is represented by a directory in proc/ .
For example spotifyd (spotify daemon) represented as a process in proc/
➜ ~ ps aux | grep "spotifyd" hackerm+ 98147 0.0 0.1 365184 13324 ? Ssl 07:15 0:00 /usr/bin/spotifyd --no-daemon
➜ ~ tree -L 1 /proc | grep "98147" ├── 98147
root/
This folder is basically considered as the home/ folder of the root user and it is only accessed by the user with root permission.
run/
This is a fairly new folder and different linux distributions use this in different ways. This folder is basically mounted as temporary filesystem (tmpfs) as this folder is wiped when the system is rebooted or shutdown and it contains programs required early in the boot procedure.
➜ ~ tree -L 1 /run /run ├── credentials ├── cups ├── dbus ├── dhcpcd ├── dmeventd-client ├── media ├── mount ├── mysqld ├── named ├── NetworkManager ├── nscd ├── openvpn-client ├── user ├── utmp └── wpa_supplicant
srv/
This is also known as service directory and this is where all the files stored that are accessed by external users when using ftp server.
sys/ .
Its also known as the system folder and this folder contains files that interact with the kernel. This directory is created when the system boots up.
➜ ~ tree -L 1 /sys /sys ├── block ├── bus ├── class ├── dev ├── devices ├── firmware ├── fs ├── hypervisor ├── kernel ├── module └── power
tmp/
This directory is known as temporary directory where files are stored by the applications that can be stored during a session. For example a word processor like libreoffice might store temporarily if the program crashes or system reboots.
usr/
This directory contains shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation.
var/
This directory contains files or directories that are expected to grow and that’s why its know as variable folder. For example you can find logs of
databases , webservers emailboxes and etc.
home/
Home directory is the storage for user files. Each user has a subdirectory in /home. This is where you will find application settings as hidden directories for example browser cache .cache/ and this is where your dotfiles live.
I have been using linux for more than 4 years now and as a linux user I have always been intrigued to explore the linux file system and its directory structure. This posts aims towards high level explanation of how filesystem works,linux file system and its directory structure. I do not intend to go over in detail about a specific filesystem such as ext4 but that’s a topic for my another blog post.
I hope you enjoyed reading this post and got to learn something new. If you think I missed anything you can always DM on twitter or EMAIL ME. Last but not least I would love to hear your thoughts.