+3 votes
305 views
Main Linux directories and containing

in Guides by (552k points)
reopened | 305 views

1 Answer

+4 votes
Best answer

What is the Filesystem Hierarchy Standard or FHS?
Main directories in Linux: content and functions.
To end.
Why does the FHS standard exist? What are the advantages of following it?
Differentiating file types according to the FHS.
The root directory /.
Directory / bin: essential command binaries at the user level.
/ boot the boot loader folder.
Directory / dev.
/ etc is the directory of configuration files.
Directory / home.
Directory / lib.
Contents of the / lost + found folder.
Folder / media
Directory / mnt.
/ opt.
/ proc.
/ root
/ run
/ sbin.
/ srv.
/ sys.
/ tmp.
/ usr.
/ var.

If you have come here it is because you would like to examine the structure of Linux directories that we find in a generalized way in the different GNU / Linux distributions. In this tutorial we collect in detail the directory tree and at the same time we will explain its content and function .

image

It is not a technical tutorial in which we will go deeper into every detail, rather it consists of a small guide in which we will make simple and concise explanations for new and advanced users.

At first it was going to be a short article, but since there are quite a few folders to explain, an article has been a bit more extensive than expected. Here you have a small index of content not to be missed:

What is the Filesystem Hierarchy Standard or FHS?

The Filesystem Hierarchy Standard is also known by its acronym in English FHS and consists of a standard that defines and normalizes the hierarchy of the file system in Unix and derived systems . In other words, this standard tells us how the directory structure should be, defining the names and contents of each directory.

The FHS standard has been created by the Linux foundation and there are distributions that follow it strictly and others not so strictly. There are also Linux distributions that do not follow this structure and redefine the file system hierarchy, for example GoboLinux.

Why does the FHS standard exist? What are the advantages of following it?

By having a standardized hierarchy of the directory tree, we ensure that programs and scripts work on different operating systems. In addition, applications and users can predict the location of programs, libraries, documentation, etc.

This standard allows defining the basic principles of the directory structure, while specifying the minimum required directories and files.

Differentiating file types according to the FHS.

The FHS standard classifies files into:

  • Static and variable : this classification differentiates directories that contain files that do not vary over time, the so-called static ones. On the other hand, those who suffer modifications over time are called variables.
  • Shareable and non-sharable : this classification allows you to distinguish shareable directories, those with files that can be used on other devices. On the other hand are the non-shareable directories, which are those that can only be used on the current device.

An example of a structure that meets the aforementioned requirements:

image

Main directories in Linux: content and functions.

Now that we have seen that the goal of FHS is to define and normalize a directory structure, I will show a list of the main directories in Linux , in which I will indicate the content and functions of each one.

The root directory /.

On UNIX operating systems, any directory structure starts from a root directory that is usually represented by the character / . This root directory works as a mount point and from it the rest of the directories and subdirectories of the tree are born.

To see the contents of the root directory, we can use the ls -la / command.

The root directory must have the following folders:

image

Directory / bin: essential command binaries at the user level.

All essential command binaries that can be used by users and by the system administrator are stored in the / bin directory. In other words, in this folder we will find the necessary tools to use the operating system at the user level.

The /bin directory cannot contain subdirectories . The tools or commands required in /bin are: cat, chgrp, chmod, chown, cp, date, dd, df, dmesg, echo, false, hostname, kill, ln, login, ls, mkdir, mknod, more, mount, mv, ps, pwd, rm, rmdir, sed, sh, stty, su, sync, true, umount and join me .

With the set of these essential tools we can use the operating system and restore the system if necessary.

/ boot the boot loader folder.

In the / boot directory, everything you need to boot the operating system is stored. All data in this folder will be used before the kernel executes the different modules and system processes.

In this folder it is common to find the GRUB bootloader and the different versions of the Linux kernel installed. In some configurations, the /boot directory is located in a different partition.

Directory / dev.

Inside the / dev directory we find the files of devices connected to the system. For example, hard drives and operating system partitions have their respective files in this folder.

You can try executing the sudo fdisk -l command that shows us the partitions present in the system. In the output information of the command you will see that in the column "Device" reference is made to the files /dev/sda of each partition. In my case the output is:

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 39845887 39843840 19G 83 Linux
/dev/sda2 39847934 41940991 2093058 1022M 5 Extended
/dev/sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris

If we connect an external storage device, the file that we can see with the fdisk -l command and which refers to this device will have a name similar to /dev/sdb .

/ etc is the directory of configuration files.

The / etc directory is one of the best known, in this we find the configuration files of the operating system's own programs and of programs installed by the user.

This directory is where we usually find the Apache server configuration files, of which we have already spoken several times. We will also find the famous passwd file where the information of the users of the system is stored.

To meet the FHS requirements, the /etc folder cannot contain binary files .

Directory / home.

Within the / home directory, all users' personal files are stored. Each user has their own folder inside the /home directory. If for example there are users Juan, Manuel and Zeokat, they will have their respective personal folders in the directories:

/home/Juan
/home/Manuel
/home/Zeokat

In the FHS specification there is no mention of the /home directory, although it is present in virtually all Linux distributions. These folders are used to store files such as photos, videos, documents, custom user settings, etc.

In most Linux distributions, we can refer to the personal directory of the active user with the ~ symbol . For example, if my user is Zeokat, I can verify that the ls -la ~ and ls -la /home/Zeokat are equivalent.

In some custom configurations of the directory structure, it is very common to place the /home directory in a separate partition. Thus, in case of system failure and we have to recover it, the personal files of the home directory will remain intact.

Directory / lib.

The / lib directory is intended to store all the essential libraries to boot the operating system and for the binaries of the / bin and / sbin folders to work. Within this folder are also kernel modules.

When an operating system operates under the 64-bit architecture , the /lib64 directory /lib64 to store the specific libraries of this architecture.

Contents of the / lost + found folder.

This folder is not found in the FHS specification, but today it is very common to find it in the root directory, so we will explain what its purpose is. In the / lost + found folder are the files and folders that have been recovered after running the fsck tool.

The files are stored in this folder because they are data that has had a name and location but has been lost. The content of these files may be corrupt or incomplete, but sometimes we can recover important data.

Folder / media

The / media directory serves as a mount point for removable devices (USB sticks, external hard drives, etc.) . They are devices that are mounted temporarily. Within this directory a subdirectory is usually created with the name of the user who has connected the removable device.

Directory / mnt.

It is an empty directory that serves as a mount point for temporary file systems. Reading the above description we can think that it is the same as the directory /media and in effect they are similar, but not the same.

The main differences between the / media and / mnt directory is that the first one is used automatically by the system, while the / mnt directory is usually used by the system administrator to mount file systems temporarily.

/ opt.

It is a directory in which additional software packages are stored. These packages are already pre-packaged with a directory structure that does not follow the standards established by UNIX.

There are many articles that resemble the /opt folder with the "Program Files" folder in Windows. Within this folder, we will find each package or application represented by a subdirectory.

The applications installed in / opt are said to be self-contained, because each package contains all the files and libraries needed to function. This has the disadvantage that space can be wasted by duplicating libraries and other files. On the other hand, it offers the advantage that removing or installing a program manually is very simple, although with current package managers there is no excuse.

/ proc.

In the / proc directory we find files and folders in which we will find information about the operating system and about processes that are running. The entire file system of this folder is virtual, it is created by the kernel itself in memory, so it does not physically exist on the disk .

/ root

In the / root folder we find the specific directory of the root user or superuser of the system. We can match it with the /home directory, but in this case it is specially designed for the root user.

/ run

In the / run folder we can find files related to processes that have been executed or that may be running. In current systems the /run folder is replacing the /var/run that was used in the past.

/ sbin.

This / sbin directory contains all the binaries of the superuser tools for system administration. To access these tools we need to be identified as a root user.

The commands available in this folder allow us to manage important aspects such as operating system boot, file restoration, system repair, etc.

/ srv.

Inside the / srv folder we find the data that can be served by the system. For example, if we have some type of server installed (web, ftp, dns, mail, etc.) , this can serve data from its own folder within /srv .

/ sys.

The / sys directory can be seen as an evolution of the / proc directory, since the contents are similar, that is, information about the system and its processes. This /sys folder also employs a virtual file system called sysfs , which represents information in a more orderly way than its predecessor /proc .

/ tmp.

As we can deduce from its name, files are stored temporarily in the / tmp folder. We cannot consider that the files stored in this folder are kept in no time, however short.

The general recommendation is that the files in this folder be deleted automatically at each system restart.

/ usr.

The / usr directory takes its name from the acronym in English User System Resources . In this folder we will find read-only files that correspond to the commands and user tools .

When we install a program through a package manager, it is usually installed within some subdirectory of this folder. The required subdirectories are:

image

/ var.

Inside the / var directory is where we will find information related to the operating system and its programs. For example, we can find statistics, action log files, error log files, cache files, etc. The files in the /var folder contain variable data and sometimes can even be stored temporarily.

If we have a problem with an application, going to this folder for error logs is usually very helpful.

To end.

In the end I have extended more than I intended, but I think I have made it clear how the different folders are organized on Linux operating systems . If at any point I have not been clear enough or you detect an error, I beg you to let me know.

Remember that the directories that we show in this article are the most common and in some distributions they can be organized in another way. For example, in Ubuntu the folder /snap has recently been included, where all distributed applications are installed as Snap packages.


by (3.5m points)

Related questions

+3 votes
1 answer
+5 votes
1 answer
+3 votes
1 answer
asked Aug 9, 2019 in Guides by backtothefuture (552k points) | 207 views
+3 votes
1 answer
+3 votes
1 answer
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users