The Linux Directory Structure
If you work with both Windows and Linux operating systems, you will notice the difference in the two file systems. Linux directories are hierarchically placed together with the root directory and do not have driver mode.
Linux directories are each responsible for maintaining part of the file and data related to the system and users, of which root, bin, home, and usr are the most important.
In the Linux operating system, everything is a file, from the file itself and the directory to the mouse and printer are all files. If you’ve finally decided to familiarize yourself with the file structure and most important directories in Linux, this article is a good place to start:
Linux directory structure
In Linux/Unix, everything is based on the file system, and this file system consists of different directories. Directories are called folders in Windows. The base of the Linux file system is the root directory, denoted by “/”.
Some Linux directories can be on partitions, drives, or even on different systems but be part of the same file system.
It is enough to pay attention to the tree structure of Linux directories to understand their position in the file system before getting to know the use of each of them:
15 main Linux directories
Now it’s time to get to know the details of each of the directories related to the Linux file system:
1) root
The root directory, denoted by /, is responsible for storing all Linux directories. Everything on a Linux system is a subtree of this directory. The path to each file and directory starts from the root; For example, if a file is located in /home/user/documents, its directory structure is as follows:
root->home->user->documents
Even if you enter the root directory with the cd command and the ls command, all the directories in the system will be displayed to you because this directory is the parent of all Linux directories.
An interesting topic!
Since the root is the root of all Linux directories, if you enter the command “/rm -rf” out of curiosity, everything you have on your system will be deleted and gone, so it’s best to ignore this technique unless you absolutely have to. Do it.
If you don’t know much about the use of Linux commands and you want to learn about the most important ones, we recommend that you don’t miss the article “The most used Linux commands”.
2) bin
This directory contains the execution files of many basic Linux commands such as cd and ls, as well as the main system applications. Most of these files are in binary form and are available to all Linux users.
The necessary files in this directory must be present when installing the operating system in single-user mode. These files are related to common commands and programs that all users can use. This directory itself does not contain any other directory, and its contents are binary files.
For example, programs such as Firefox, which are not among the main and essential programs, are stored in /usr/bin directory, but important tools such as bash shell are located in /bin.
The sbin directory is similar to bin, except that all the binary files in this directory can only be executed by the root or sudo user. You can think of this extra “s” as super or sudo.
3) boot
boot is one of the main Linux directories where all the files necessary to boot the operating system are stored. Boot loaders, kernel-related files, conf, LILO, and Grub are located in this section. Therefore, it is recommended that this directory be placed in a partition on the first disk.
In fact, the initial ram file system or initramfs is stored in this directory along with the kernel. So, working with this directory requires special sensitivity, and you should not manipulate the files in this section in any way, and if you are curious to try some things, it is better to use a virtual machine.
4) dev
dev is where all the devices related to your system such as keyboard, mouse, printer, etc. live there. You can access different parts of your hardware with this directory. For example, the device partition is accessible with /dev/sda1. In fact, all programs and drivers have access to this directory.
Of course, the files in this directory are virtual, representing the implementation of the hardware connected to the system, and are not physically located on the disk.
This directory also contains pseudo-devices that have nothing to do with hardware. For example:
/dev/null which is a string used to delete any file.
/dev/zero contains an infinite trail of 0’s.
/dev/random contains an infinite sequence of random values.
5) etc
This directory contains all configuration files necessary to control the operation of system programs. etc is primarily used by admins and services to configure network and password files.
Startup scripts, network files, user account files, etc. are important configuration files whose editing in the etc directory causes new changes to be applied to the entire system.
Of course, note that the configuration files in this directory are related to the entire system, and each user’s specific configuration files are located in the user’s home directory.
6) home
In the Linux system, each user has his own directory that the user and the system administrator can only access. The home directory is the directory where the user stores his personal files and installs programs. This directory also contains the user’s configuration files, which are marked with a dot (.) before the file name.
For example, if the system has two users named Alexi and Roza, each has their own file and program list in home/Alex and home/bob.
Note that Ali cannot access Reza’s files and vice versa. It makes perfect sense for each user only to have access to their own home directory.
7) lib
lib, as one of the most important Linux directories, is the location of kernel modules and shared library files. The *.so extension can easily identify the libraries in this section. Modules are located in the path “lib/modules/”.
The libraries in this directory can be used in the process of executing the commands in the bin directory. Of course, the libraries needed to run the binary files in /usr/bin are located in the /usr/lib path.
8) media
The media directory contains the contents of removable media such as cd ROMs and USB disks that can be connected to the system.
When you connect a USB disk or CD and DVD to the system, a list is automatically created for it in the media directory, through which you can access the contents of that media. Of course, when you remove the media from the device, the corresponding directory is automatically removed from the system.
9) mnt
mnt is a folder where the system administrator mounts devices or file systems manually and temporarily. The meaning of mount is an operation during which a file system is made available to the operating system. Of course, some Linux distributions use mnt as a permanent storage and installation solution.
10) Opt
The opt directory as an optional directory, is the location of manually installed program codes and packages. The files in this directory are to facilitate the compatibility of some specific programs. So when you install a program that is not in the official Linux distribution, its software code is stored in the opt directory.
For example, when installing the WhatsApp program, its related files are placed in /opt/WhatsApp path.
11) usr
usr is one of the main and most important Linux directories, which includes all binary files, libraries, documents, and all user-related programs. Note that all the files in this section are not necessary for the main operation of the system.
Unlike the main programs and files of the system, the contents of this directory are only used by users, and for example, unnecessary programs and commands are located in /usr/bin instead of /bin, and the libraries related to each of them are inside the /usr directory. /lib are located. This usr has its own directories:
/usr/bin: executable files and user commands
/usr/sbin: Administrator commands for system management
usr/lib: libraries and packages necessary to run the files in /usr/bin:
/usr/include: contains header files used for c language compilers (stdio.h and stdlib.h)
12) srv
This directory, as a server directory, is where data about services is stored. For example, if you run an FTP or HTTP server, the files that external users will access are stored in this directory.
In fact, users can access the location of files related to a specific service by visiting this directory. These data files are only related to the user to whom the home directory is assigned.
13) var
var, as one of the main Linux directories, is the place to store variable files generated by the system, such as system registration, user tracking, cache, etc. For example, data related to system log files or the printer spool directory, which are expected to grow in size over time.
Files stored in this directory are not automatically deleted, so the var directory allows administrators to query the behavior of their system easily. For example, to check the log history of the Linux system, it is enough to check the contents of the /var/log/wtmp file.
Some of the files related to the directory:
var/log: contains reports about the system and various programs
var/spool: contains data that is waiting for further processing in the future, i.e. it has a dynamic state.
var/crash: stores information about processes that have crashed.
14) tmp
tmp is a place to store temporary files created by programs. For example, if you are writing a document in LibreOffice, a temporary copy of it is regularly saved in this directory and emptied when the system is restarted.
Of course, sometimes you may see files that are not deleted because the system is not able to delete these files, which you can delete manually if you want. In general, since this directory is deleted every time the system is started, try not to put anything important in this directory.
15) proc
The proc directory contains information about running processes and kernel parameters, which processes are identified by specific IDs. Some tools use the contents of this directory to get runtime system information.
For example, to check the information about the processor of the Linux system, you can easily refer to the file /proc/cpuinfo or to know the amount of memory usage, you can refer to the content of the file /proc/meminfo.
These files are filled when the system is started, but they are completely empty when the system is turned off.
* If you are thinking of buying a Linux virtual server, you should know that this operating system benefits from wonderful commands and directories that you can use to manage your server more efficiently.