Home> System Tutorial> LINUX> body text

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

PHPz
Release: 2024-02-15 12:18:28
forward
358 people have browsed it

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

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

source:lxlinux.net
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!