🎯Understanding Linux FileSystem Hierarchy

🎯Understanding Linux FileSystem Hierarchy

Β·

6 min read

Let's try to understand how Linux Operating System organizes files and directories. Everything in Linux is a fileπŸ“. In windows, the hard drive is commonly represented as C: or a small symbol of the hard driveπŸ“‚ with the space occupied in file explorer. Whereas in Linux, however, its simply represented as a directory, which is just a file.

The Linux operating system has a special place called Linux FileSystem Hierarchy Standard(FHS) maintained by the Linux foundation. It has a hierarchical structure which keeps the files organized and standardized.

In this article, we'll be learning about each folder in the Linux file system hierarchy and their uses.

πŸ“Œ/ directory

In Linux, the / or root directory is the highest level directory in the filesystem hierarchy. Its visual representation is forward slash / . It is the starting point of all directories and the file paths on the system. This contains the whole entirety of the operating system.

In the above snap, I used cd(Change Directory) command to change my current directory to / directory and then I used ls(List of Files) command to show the list of directories that are present inside the root.

So the / directory act as a parent directory and the rest directories like /home, /bin, /lib . etc are child directories of / .

Let's start one by one,πŸ€”

πŸ“Œ/bin

The /bin directory contains the most essential terminal commands such as ls, cat, pwd and touch so on. These ready to run commands are available system-wide meaning all users can access them. Here the program files are designed in binary format, which are easily understandable to computers.

πŸ“Œ/boot

As the name suggests, this directory contains the most crucial files such as Linux-kernel, bootloader configuration files and other boot related files, that are required by the operating system to boot properly. These boot files should not be deleted or modified by the users.

πŸ“Œ/dev

This directory stands for "devices" and represents all the physical devices such as hard drives, USB ports, and so on that are connected to the system. In Windows, when you go to β€œMy Computer” you see all of the physical devices and drives connected to your computer, just like that in Linux the devices are mounted in /dev in Linux file structure.

πŸ“Œ/proc

These directory represents the virtual file system exposing the system statistics in the form of files. It contains information about currently running processes. Users can read and write to these files to get information about system hardware, processes, and kernel settings.

πŸ“Œ/etc

These core directory in Linux stands for "et cetera", pronounced as EHT-see where system configurations files are stored. It contains the information about Linux user's data and passwords, network settings, and other important system information. Here in the above snap you can see most of the configuration files have .conf extensions.

πŸ“Œ/home

This directory is for regular users, stores users personal informations. It contains the Documents, Downloads, Photos, Videos and the configuration files for the applications installed for each particular users. This allows each user to have their own set of programs and applications without interfering with other users' settings.

Note:- home directory is for other users except root user.

πŸ“Œ/root (not "/")

This directory in Linux is the home directory of the root user. The root user is a special administrative user with full privileges to perform any action on the system. The root user's home directory contains various subdirectories similar to regular user's home directory, like Desktops, Documents, Pictures and videos. However, these directories are typically used for system-related files and configuration settings rather than personal files.

Note:- /root directory is not the same as the root directory "/" , which is the starting point for all directories and files in the Linux file system.

πŸ“Œ/run

This directory in Linux is created dynamically to stores runtime data of processes running on the system. The files stored in /run includes process IDs, socket files, status records and lock files.

Its a temporary filesystem usually stored in the RAM of the system. The data stored is automatically cleaned up when the system is shut down.

πŸ“Œ/lib

The /bin directory in Linux stands for "libary", contains shared library files that are required by the system and applications. When you installed Linux software packages, you’ll notice that additional libraries are downloaded sidewise. These are the files required for your Linux apps to function properly.

Its same as Program Files folder in Windows.

There are two types of libraries static and shared, the /lib is usually holds for necessary shared libraries, while additional libraries or both are used by applications are typically located in other directories such as /usr/lib or /usr/local/lib.

πŸ“Œ/sys

The /sys directory in Linux is same as /proc directory, provides the standarized information about the drivers and specially kernels.

The directory contains crucial details of system devices like input/output (I/O) devices, network interfaces, and storage devices. Additionally, it holds information regarding system status, including power management settings and system clock configurations.

πŸ“Œ/var

The /var directory in Linux stands for "variable", contains files and directories that may change in size and content over time during the system's operation.

This directory contains files such as system logging, backups, crash logs, caches, metrics and some other log files as well.

πŸ“Œ/tmp

This is the area where temporary files are stored that are needed only for short period of time and they are usually deleted upon next boot or application restart.

Any user to read and write in/tmp, but user don't have the permission to access other user's file here.

πŸ“Œ/sbin

This directory stands for "system binaries", a place for system executables(commands) for system management like adding users, networks, and passwords. Program in /sbin is related to system administrator, so regular user can't avail it.

Many utilities here required administrative privileges, for that you need superuser or root user permissions to execute commands in this directory.

πŸ“Œ/usr

This directory stands for "user", contains all the files, directories and utilities shared with all the users of the system. Its basically read only data.

It originally contained home directories but now it also contains the /bin, /sbin and /lib folders. The bin folder contains commands like ls, touch, pwd and cat that is executed from the terminal.

πŸ“Œ/opt

The /opt directory stands in Linux for "optional", used for installing the optional software packages that are not provided by your flavour's distributions software packages.

These programs are typically third-party programs that we install on our system.

πŸ“Œ/media

This directory in Linux is used as mount point for removable media devices such as USB drives, external drives, CD-ROMs, and DVDs. Whenever a new removable media device is inserted into the computer, the system will automatically create corresponding directory in /media and the contents of the device will be accessible inside the directory.

This directory is used by the system to automatically mount and unmount the removable media.

πŸ“Œ/mnt

This directory is used for temporarily mounting file systems. Here /mnt stands for "mount" and the directory is used typically to mount file systems specially network file systems, removable media (e.g. USB drives, CD/DVDs), and other local file systems.

Note :- Both /media and /mnt are used for mounting files systems, but the only diffrence between them is /media automatically mount and creates the space when removal devices is inserted while /mnt is used for manually mounting file systems as well as for system administrators to temporarily mount file systems.

Conclusion

As we moved to the end, I hope this article helps you to understand the concepts of Linux FileSystem Standard(FHS). It is important to understand their purpose and location.

Stay tuned for deep diving into the field of Linux.

Thankyou ! and Happy Learning πŸ’–

Β