Hi Everyone! I’m back with the new blog, Today I will be discussing about the Linux File System. Have you ever saw various directories in your Linux systems and wonder why even they exist. Why can’t we just have a single directory and keep everything in it?

Introduction to Linux file system

Linux File System is a method of organizing and storing various information in a way that it can easily manage. Every data in the Unix system manged through files. These files organized in directories. A combination of these files and folders creates a file system.

As you can see in the above diagram a representation of directories, you’ll get in every Linux/Unix system.

Why we need the linux file system?

Assume you are working on a project which is in a directory, it requires multiple files and folders :

Binary files

Configuration files

Log files

Data files

Metadata files during execution

Libraries

You are keeping everything in a single directory then it’ll look like the same as above in the picture. If another software comes into the picture which has its own configuration files.

Things will be very messy to manage the same type of files for each and every software, It will not be easy to manage everything and will lead to chaos and it is not necessary that everyone follows the same convention if a new person comes into the picture then he’ll manage his files in his own way that will make it difficult to understand the hierarchy of file systems.

To avoid this situation the creator of Unix followed a philosophy “Convention over Configuration“. Using this everyone will be on the same page and will follow the same convention and it will make easy to understand the hierarchy for everyone

According to this philosophy, the same type of files will be kept in the same directory it will look like something as follows:

Binary files — — — — — — — — — — — — -> /bin

Configuration files — — — — — — — — — — — — -> /etc

Log files — — — — — — — — — — — — –> /log

Data files — — — — — — — — — — — — –> /var

Metadata files during execution — — — — — –> /tmp

Libraries — — — — — — — — — — — — –> /lib

Something like in the following picture:

Lets go and discuss some important directories which plays a major role in Linux/Unix file system:

/ (slash): This is the root directory of the overall filesystem, it resides at the top of the hierarchy of file system, which means every file and folders resides in it.

This is the root directory of the overall filesystem, it resides at the top of the hierarchy of file system, which means every file and folders resides in it. /bin : It stands for “binaries” and contains all the basic operations (e.g. cp, ls, mkdir etc )without which you can not do anything in your OS. This directory consists of all the binaries created by C compiler and shell scripts.

: It stands for “binaries” and contains all the basic operations (e.g. cp, ls, mkdir etc )without which you can not do anything in your OS. This directory consists of all the binaries created by C compiler and shell scripts. /etc: This directory contains all the configuration files over the system-wide. It consists of various services or daemons running on the OS. It makes sure everything works fine the way you want.

This directory contains all the configuration files over the system-wide. It consists of various services or daemons running on the OS. It makes sure everything works fine the way you want. /var: It stands for “variable” . It contains files to which the system writes data during the life of its operation. Among the various sub-directories within /var are /var/cache (contains cached data from application programs), /var/games(contains variable data relating to games in /usr), /var/lib (contains dynamic data libraries and files), /var/lock (contains lock files created by programs to indicate that they are using a particular file or device), /var/log (contains log files), /var/run (contains PIDs and other system information that is valid until the system is booted again) and /var/spool (contains mail, news and printer queues.

It stands for “variable” . It contains files to which the system writes data during the life of its operation. Among the various sub-directories within /var are /var/cache (contains cached data from application programs), /var/games(contains variable data relating to games in /usr), /var/lib (contains dynamic data libraries and files), /var/lock (contains lock files created by programs to indicate that they are using a particular file or device), /var/log (contains log files), /var/run (contains PIDs and other system information that is valid until the system is booted again) and /var/spool (contains mail, news and printer queues. /lib : Contains system libraries, and some critical files such as kernel modules or device drivers.

Contains system libraries, and some critical files such as kernel modules or device drivers. /mnt : Stands for “mount”. Contains filesystem mount points. These are used, for example, if the system uses multiple hard disks or hard disk partitions. It is also often used for remote (network) filesystems, CD-ROM/DVD drives, and so on.

Stands for “mount”. Contains filesystem mount points. These are used, for example, if the system uses multiple hard disks or hard disk partitions. It is also often used for remote (network) filesystems, CD-ROM/DVD drives, and so on. /proc: If you navigate to /proc The first thing that you will notice is that there are some familiar-sounding files, and then a whole bunch of numbered directories. The numbered directories represent processes, better known as PIDs, and within them, a command that occupies them. The files contain system information such as memory (meminfo), CPU information (cpuinfo), and available filesystems.

If you navigate to /proc The first thing that you will notice is that there are some familiar-sounding files, and then a whole bunch of numbered directories. The numbered directories represent processes, better known as PIDs, and within them, a command that occupies them. The files contain system information such as memory (meminfo), CPU information (cpuinfo), and available filesystems. /opt: This directory is reserved for all the software and add-on packages that are not part of the default installation.

This directory is reserved for all the software and add-on packages that are not part of the default installation. /usr: This directory holding user home directories,its use has changed. It now holds executables, libraries, and shared resources that are not system critical, like the X Window System, KDE, Perl, etc. However, on some Unix systems, some user accounts may still have a home directory that is a direct subdirectory of /usr, /usr/bin directory stores all binary programs distributed with the operating system not residing in /bin, /sbin or (rarely) /etc./usr/include Stores the development headers used throughout the system. Header files are mostly used by the #include directive in C/C++ programming language./usr/lib Stores the required libraries and data files for programs stored within /usr or elsewhere.

Here are some basic confusions lots of people are dealing with finding the difference between some similar type of directories, Lets discuss some

/bin vs /usr/bin vs /sbin vs /usr/local/bin

This might get almost clear out when I explained the significance of /usr in the above paragraph. Since Unix designers planned /usr to be the local directories of individual users so it contained all of the sub-directories like /usr/bin, /usr/sbin, /usr/local/bin. But the question remains the same how the content is different?

/usr/bin:

/usr/bin is a standard directory on Unix-like operating systems that contains most of the executable files that are not needed for booting or repairing the system.

A few of the most commonly used are awk, clear, diff, du, env, file, find, free, gzip, less, locate, man, sudo, tail, telnet, time, top, vim, wc, which, and zip.

/usr/sbin:

The /usr/sbin directory contains non-vital system utilities that are used after booting.

This is in contrast to the /sbin directory, whose contents include vital system utilities that are necessary before the /usr directory has been mounted (i.e., attached logically to the main filesystem).

A few of the more familiar programs in /usr/sbin are adduser, chroot, groupadd, and userdel.

It also contains some daemons, which are programs that run silently in the background, rather than under the direct control of a user, waiting until they are activated by a particular event or condition such as crond and sshd.

I hope this blog will clarify the purpose of these directories so that you understand the Linux file system more effectively.