Table of Contents
/bin" >/bin
/boot" >/boot
/dev" >/dev
/etc" >/etc
/home" >/home
/lib, /lib32, /lib64, …" >/lib, /lib32, /lib64, …
/lost found" >/lost found
/media" >/media
/opt" >/opt
/proc" >/proc
/root" >/root
/run" >/run
/sbin" >/sbin
/srv" >/srv
/sys" >/sys
/tmp" >/tmp
/usr" >/usr
/var" >/var
Summarize" >Summarize
Home System Tutorial LINUX Linux file system analysis: the role and usage of each directory

Linux file system analysis: the role and usage of each directory

Feb 15, 2024 pm 12:18 PM
linux linux tutorial linux system linux command shell script embeddedlinux Getting started with linux linux learning

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

Linux 文件系统解析:各个目录的作用和用法

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.

Linux 文件系统解析:各个目录的作用和用法

/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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

Difference between centos and ubuntu Difference between centos and ubuntu Apr 14, 2025 pm 09:09 PM

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

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)

Detailed explanation of docker principle Detailed explanation of docker principle Apr 14, 2025 pm 11:57 PM

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

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.

See all articles