Linux and its way of storing files...
Tags: beginners, linux, devops
Published: 2022-03-11 12:26:54

### What is the Linux File System?

The file system is generally a *built-in layer* of a **Linux** operating system used to handle the data management of the storage. It helps to arrange the file on disk storage and manages the file name, file size, creation date, and much more information about a file.

The Linux file system is a **structured** collection of files on a disk drive or a partition. A partition is a segment of memory that contains some **specific data**. In our machine, there can be various partitions of memory. Generally, *every* partition contains a file system.

The files are stored in the **hierarchical tree structure**. **Root** folder comes *first and then files are under root respectively*. Whereas in **windows**, files are stored in folders on different data drives like **C: D: E:**

![lfs.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1647000173389/W2DM3J63I.jpg)

### Linux File System Overview

![Filesystem Hierarchy Structure (FHS) in Linux – TecAdmin](https://tecadmin.net/wp-content/uploads/2022/06/linux-filesystem-hierarchy.png)

`/` *or* `/root` =&gt; root user's home directory which is separate from other users

`/home` =&gt; contains the home directories of all non-root users.

`/bin`*(stands for binaries)* =&gt; executables for most essential user commands(all files are system-wide usable)

*What is binary?*

*A binary is just a computer-readable format (a bunch of 0's & 1's)*

`/sbin`*(system binaries)* =&gt; essential system binaries, programs that admin would use(need superuser privileges)

`/lib, /lib32, /lib64, /libx32` =&gt; essential shared libraries that executables from `/bin` or `/sbin` use.

`/usr`*(user)* =&gt; this was used for user home or directories*(contains the same* `/bin`*,* `/sbin`*,* `/lib` *folders)*.

*Why do* `/usr` *contain these folders?*

* *historic reasons(as UNIX also had those splits)*
    
* *Because of storage limitations, it was split to root binary folders ad user binary folders.*
    

**NOTE:** When we execute basic Linux commands they are executed from `/usr/bin` folder. In other distros, `/bin` or `/sbin` contains fewer commands and `/usr/bin` or `/sbin` contains all other commands.

Inside `/usr`, there is a folder `/local` that also contains the same files as `/usr`(`/bin` or `/sbin` or `/lib`).

`/usr/local` =&gt; programs that you install on the computer. Third-party applications like docker, minikube, etc go here. Programs installed here will be available for all users on the computer.

**NOTE:** If you want to install third-party applications and don't want to be accessed by all the other users then you install them on your own `/home` directory.

`/boot`*(booting)* =&gt; contains files required for booting.

`/opt`*(optional)* =&gt; third-party programs you install(all programs will be available system-wide).

**Difference between /usr/local & /opt:-**

* `/usr/local`: programs that split into their components.
    
* `/opt`: programs which not split into their components.
    

**NOTE:** Till now all folders are *read-only* folders.

`/etc`*(et cetera)* =&gt; a place where the configuration for system-wide applications is stored. Originally for etc*(means everything else goes there)*. It emerged into the main configuration location.

`/dev`*(devices)* =&gt; location of device files like webcam, keyboard, hard drives, etc. Apps and Drivers will access this, **NOT** the user.

`/var`*(variable)* =&gt; contains files to which the system writes data during the course of its operation.

`/var/log` =&gt; contains log files.

`/var/cache` =&gt; contains cached data from application programs.

`/tmp`*(temporary)* =&gt; temporary resources required for some processes kept here temporarily.

`/media`*(removable media)* =&gt; contains subdirectories where removable media devices inserted into the computer are mounted. For example, when you insert a CD, a directory will automatically be created and you can access the contents of the CD inside the directory.

`/mnt`*(temporary mount points)* =&gt; historically, sysadmins mounted temporary file systems there(or manually mounting folders).

### Interacting with these folders

Usually, you are **not** interacting with these folders. Installing apps with a package manager is responsible to store the required files in the right corresponding folders.

### Hidden Files

These are primarily used to help prevent important data from being accidentally deleted and are automatically generated by programs or operating system. The file name starts with `.`*(dot)*. These are also called *'dotfiles'*.

![hide-folders-ubuntu-linux.webp](https://cdn.hashnode.com/res/hashnode/image/upload/v1647000967107/fjE4-yMJl.webp)