Understanding the Linux System Directory Structure

๐Ÿง Understanding the Linux System Directory Structure

“The root directory of the Linux system is like the root of a large tree, from which all files and folders grow.”

๐ŸŒฒ 1. Starting with <span><span>ls /</span></span> command

After logging into the Linux system, enter the command:

ls /
ไฝ ไผš็œ‹ๅˆฐไธ€ไธฒ็œ‹ไผผๅคๆ‚็š„็›ฎๅฝ•๏ผŒๅฆ‚ๅŒไธ€ๆฃตๆ ‘็š„ๅˆ†ๆžใ€‚่ฟ™ๅฐฑๆ˜ฏ Linux ็š„ 
ๆ น็›ฎๅฝ•็ป“ๆž„ใ€‚

๐Ÿ“‚ 2. Detailed Explanation of Common Linux Directories

Below is an explanation of the functions of each directory๐Ÿ‘‡

๐Ÿ”ง /bin

Binaries is an abbreviation for binary files, which store the most commonly used commands in the system, such as <span>ls</span>, <span>cp</span>, <span>mv</span>, etc.๐Ÿ‘‰ It is equivalent to a “toolbox” that the system cannot run without.

๐Ÿš€ /boot

Contains essential files for system booting, such as the kernel image and bootloader (<span>grub</span>).โš ๏ธ Do not modify it casually, as it may prevent the system from booting.

๐Ÿ’ฝ /dev

Device is an abbreviation for device files, which store all external device files in the system.๐Ÿ‘‰ In Linux, devices are also files; for example, <span>/dev/sda</span> represents the hard disk.

โš™๏ธ /etc

Etcetera is an abbreviation for various configuration files of the system.Common examples include:

  • <span>/etc/passwd</span>: User information

  • <span>/etc/fstab</span>: Disk mount informationโš ๏ธ Please back up before modifying, as it may prevent the system from booting!

๐Ÿ  /home

The home directory for users. Each user has an independent home directory, such as <span>/home/alice</span>.๐Ÿ‘‰ All personal files, downloads, and desktop files are stored here.

๐Ÿ“š /lib

Library is an abbreviation for the basic dynamic link libraries of the system (similar to Windows DLL files).๐Ÿ‘‰ Almost all programs need it to run.

๐Ÿงฉ /lost+found

When the system shuts down abnormally or crashes, recovered fragment files will temporarily reside in this directory.Generally, it is empty.

๐Ÿ’พ /media

Auto-mount directory. When a USB drive or external hard drive is inserted, the system will automatically mount it under <span>/media</span>.

๐Ÿงฑ /mnt

A directory provided by the system for temporary mounting of file systems.For example, you can mount a CD drive to <span>/mnt</span> and then access the contents of the CD.

๐Ÿ“ฆ /opt

Optional is an abbreviation for storing additional installed software packages.For example, when installing software like Oracle or Chrome, it may be placed here.

๐Ÿ” /proc

Processes is an abbreviation for a virtual file system that stores content in memory rather than on disk.๐Ÿ‘‰ It records system running status, process information, etc.For example:

echo 1 &gt; /proc/sys/net/ipv4/icmp_echo_ignore_all

This can temporarily suppress the system’s ping response.

๐Ÿ‘‘ /root

The home directory of the superuser (root).โš ๏ธ It has very high permissions, and ordinary users generally do not have access.

๐Ÿงฐ /sbin

Superuser Binaries stores management commands used by system administrators, such as <span>reboot</span>, <span>ifconfig</span>, etc.

๐Ÿ”’ /selinux

A directory specific to RedHat/CentOS.It stores files related to SELinux (Security-Enhanced Linux) for access control and security management.

๐Ÿ›ฐ๏ธ /srv

Stores data provided by services after they start, such as data directories for Web and FTP services.

โšก /sys

A directory added after the Linux 2.6 kernel, which mounts the sysfs file system to display the system device tree.๐Ÿ‘‰ It can be understood as:the mapping view of system hardware in the kernel.

๐Ÿงน /tmp

Temporary file directory used to store various temporary data.It is usually cleared after a system reboot.

๐Ÿง‘๐Ÿ’ป /usr

Unix System Resources is an abbreviation for storing user applications, system commands, and documentation, and is one of the largest directories.It is similar to Windows’ <span>Program Files</span>.

/usr/bin

Directory where executable programs for ordinary users are located.

/usr/sbin

Advanced commands used by system administrators.

/usr/src

Default directory for kernel source code and development files.

๐Ÿ“ˆ /var

Variable is an abbreviation for storing frequently changing data, such as logs, caches, emails, databases, etc.Common subdirectories include:

  • <span>/var/log</span>: System log files

  • <span>/var/mail</span>: Mail storage directory

๐Ÿ‘‰ If system logs accumulate too much, it may also lead to insufficient disk space.

๐Ÿ”„ /run

Temporary runtime information storage after the system starts.After a system reboot, the contents of this directory will be cleared.In some systems, <span>/var/run</span> will be a symbolic link to <span>/run</span>.

๐Ÿšซ 3. Directories to be Particularly Cautious With

โš™๏ธ <span>/etc</span>

The core configuration directory of the system.๐Ÿ“Œ Stores all configuration files for the system and services, such as network settings, user information, startup items, etc.โš ๏ธ Be sure to back up before modifying, as incorrect configurations may cause the system to fail to boot directly.

๐Ÿงฐ <span>/bin</span>, <span>/sbin</span>, <span>/usr/bin</span>, <span>/usr/sbin</span>

Storage locations for executable commands in the system.For example, the most commonly used command <span>ls</span> is located at <span>/bin/ls</span>.

๐Ÿ“Œ In simple terms, their differences lie in the different users:

  • <span>/bin</span> and <span>/usr/bin</span>: Regular commands for ordinary system users, such as <span>ls</span>, <span>cp</span>, <span>cat</span>, etc.;

  • <span>/sbin</span> and <span>/usr/sbin</span>: Management commands for system administrators (root), such as <span>reboot</span>, <span>ifconfig</span>, <span>mount</span>, etc.

๐Ÿ’ก You can understand it as:

<span>/bin</span> series is the “toolbox for everyone”,<span>/sbin</span> series is the “control panel for administrators”.

โš ๏ธ Never delete or move these commands, as it may cause system functionality to fail.

๐Ÿงพ <span>/var</span>

The system’s “record warehouse”.๐Ÿ“Œ Stores log files, caches, emails, databases, and other dynamic data.โš ๏ธ Be particularly careful when cleaning logs or caches, and do not accidentally delete critical system log directories (such as <span>/var/log</span>).

๐Ÿงญ 4. Conclusion

The directory structure of Linux is like an orderly world: each directory has its own mission for the system to operate stably.

๐Ÿ”น <span>/</span> is the root๐Ÿ”น <span>/bin /sbin</span> is the command repository๐Ÿ”น <span>/etc</span> is the brain๐Ÿ”น <span>/usr</span> is the resource center๐Ÿ”น <span>/var</span> is the recorder

Understanding the directory structure is to understand the soul of Linux.

๐Ÿ’ก Final Note

If you are new to Linux, it is advisable to start by familiarizing yourself with these directories.Every time you type <span>ls /</span>, you are greeting the “tree of life” of the operating system.๐ŸŒณ

Leave a Comment