Linux file system analysis: the role and usage of each directory
The Linux file system is a complex and organized structure that contains all the files and data required by the operating system and users. There are many different directories in the Linux file system, each with a specific meaning and purpose. If you want to better understand and manage your Linux system, you need to know what these directories are, what they store, and how to use them correctly. In this article, we will introduce you to the most common and important directories in the Linux file system, including /bin, /boot, /dev, /etc, /home, /lib, /lost found, /media, /mnt, /opt, /proc, /root, /run, /sbin, /srv, /sys, /tmp and /usr.
/bin

This is the primary storage location for executable binaries required by the system (hence the name "bin"). These basic binaries are required by the system during the boot process to ensure successful completion. Here you will find basic commands like ls and top.
During the boot process, if /usr/bin is not available, /bin is sometimes provided as a symbolic link at the top level.
/boot
This directory contains all the key files needed to actually boot the operating system. These include kernel files, boot loader files (such as GRUB), and EFI files for modern UEFI systems.
For Linux systems, this directory is one of the most important directories, because if something goes wrong here, your system may not be able to start, or you may not even know where to start.
/dev
/dev is short for "device", which is where Linux stores references to most connected devices on the system, both physical and virtual. Here you can find references to hard drives, USB peripherals, virtual terminals, and even empty devices that you can direct things to so that they disappear.
If you access any kind of device from the command line, even if it's not physical hardware, chances are it exists here.
/etc
Most likely you have researched in the /etc directory before. This is where Linux keeps all its core configuration files, not only for its own programs, but also for third-party programs you install.
If you need to modify the way the program runs, core network settings, or crontab, they all exist in this directory.

/home
This is one of the more descriptive top-level directories. This is exactly where the user's home directory is. Think of it as a separate space that each user has within the operating system. Typically, they own all files and subdirectories in their corresponding home directories.
If you view this directory on a shared machine, you may find many subdirectories named after each specific user. After logging in on most systems, you can reference your home directory using the ~ character in the path. The corresponding path is /home/.
This is the best place to store personal files that are relevant only to you. Pictures, music files, spreadsheets, or the next great novel should all be stored here. You should not store shared program configuration or system-level data here.
/lib, /lib32, /lib64, …
These directories contain shared C libraries and kernel modules. These modules and libraries are the basis for the executable binaries in the /bin directory we mentioned earlier. In other words, in order to actually boot the operating system and use any default binaries, we need the library files in these directories.
Note: If there are multiple library files for different architectures, you will see other lib directories exist.
/lost found
This directory is very simple. Here you will find some files that are corrupted but attempts have been made to recover them. This is usually caused by an unexpected power outage or sometimes a hardware failure.
/media
This is also very intuitive. This is a mount point for mounting removable media. Historically, it was used on CDs, floppy disks, and even Zip disk drives. Now, if you mount any virtual ISO or CD images, they can appear here, along with USB flash drives and other removable flash media.
/mnt This is a more general mount point where you can mount removable media or an entire file system. Today, this is typically used to house external disks, NFS, and other remote file storage.
This directory is empty, you can decide what to mount here and how to mount it.
/opt
This is the abbreviation of "option" and was originally used to store any additional software packages. These packages are not included with the original release of the system and require additional cost.
Today, this is one of the few places where add-on packages can be installed (with or without additional cost). In some cases, the distribution may not use /opt at all, but this is one location where you will find third-party package data and their static configuration files.
/proc
This is a unique Linux directory. You won't store anything here, and in fact the operating system won't store anything here. This is the information center for the Linux kernel. All "files" in this directory are not ordinary files. They contain metrics about processes, memory, and other subsystems. These special files are like windows into the workings of the kernel.
By simply reading the files in this directory, you can obtain some of the same data that other binaries obtain.
/root
This is another simple, intuitive directory. This is the root user's home directory. If you are logged into the system as the root user, you will find that your home directory is now /root instead of /home/root as expected. This is for security reasons in case /home is mounted on an inaccessible or worse, broken remote partition.
/run
This directory handles more startup and runtime information. Typically you will find the process ID or PID file in this location. These files describe where a process runs so that other programs can later find it and control or reference it.
In addition, other temporary files can be placed here, such as lock files and socket information. This directory is intended to hold runtime information, not persistent data.
/sbin
Similar to /bin, the /sbin directory also contains executable binary files required by the system. The difference is that the binary files in this directory have special purposes. They are both specifically designed to perform administrator functions on the system. This means they are powerful enough to make significant modifications or maintenance to the operating system, so they are usually found here.
You won't find binaries like echo or cat here. This directory is reserved for tools like fdisk or usermod.
/srv
This is another very general directory. This directory is used to store files that the system is responsible for "providing". For example, if the host was a web server, you might place all your HTML and image resources here.
/sys
Depending on the distribution you are using and its version, you may or may not have a /sys directory on your system. This directory is similar to the /proc directory in that it contains device and kernel information, but is presented in a more structured format.
/tmp
Another simple directory. This is a directory for temporary files. You can store almost anything you (or the program) like here, but you can't expect it to last forever. Especially between reboots.
If you need to stage some unimportant data or check the output format of a certain file, putting it here is an option. An added bonus is that if you forget about it, it will probably disappear on its own.
/usr
This directory may require writing a special article to introduce it. According to the Linux Foundation's FHS specification, it is described as:
"Shared, read-only data."
This essentially means that it should be able to be easily transferred between hosts and have the same unmodified structure and hierarchy. Normally, this directory does not contain any unique host data. The idea behind this is that the entirety of /usr can be mounted in read-only mode on another system without problems.
However, in practice, this directory is indeed used to store arbitrary information. In some cases, you will find files in /usr/share or /usr/local. You will also find program compilations or custom scripts placed in /usr/local/bin.
Generally speaking, it is recommended to store configuration or special data that does not fall into any of the previous categories in our next and last directory.
/var
This is the abbreviation of "variable", and this is where the variable data is saved.
Here are some of the things traditionally kept here:
- Printer spools
- Lock files
- Debian apt and other running program caches
- Email data
- Logs The main purpose of the
/var directory is to hold any dynamic data used and changed by the system at runtime. If you need to write to logs or keep a dynamic .conf file somewhere, you've come to the right place.
Additionally, there is the /var/local directory, which in my experience often becomes a comprehensive storage directory for miscellaneous configuration files and other data that doesn't quite fit into other categories.
Summarize
Through this article, you should have a clearer understanding of each directory in the Linux file system, know their meaning and purpose, and how to choose the appropriate location according to different types of files. The Linux file system is a carefully designed structure that provides the operating system and users with an efficient, secure, and flexible file management method. Mastering the knowledge of Linux file systems can allow you to better use and maintain Linux systems, and can also avoid some common mistakes and problems.
The above is the detailed content of Linux file system analysis: the role and usage of each directory. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.
