The Linux file system uses a tree-like structure, and all files and directories start at Root Directory (/)。
Diagram of the Linux File System Structure
graph LR
Root["/ (根目录)"]
subgraph sg_core [核心系统]
Usr["/usr/"]
Boot["/boot/"]
LinkBin["/bin, /sbin, /lib*"]
end
LinkBin -.-> Usr
Root --> Usr
Root --> Boot
Usr --> UsrBin["bin/ (git, python3)"]
Usr --> UsrSbin["sbin/ (nginx)"]
Usr --> UsrLocal["local/ (手动安装)"]
Usr --> UsrLib["lib/ (库文件)"]
subgraph sg_data [配置与数据]
Etc["/etc/"]
Var["/var/"]
Tmp["/tmp/"]
end
Root --> Etc
Root --> Var
Root --> Tmp
Etc --> NginxConf["nginx/"]
Etc --> Systemd["systemd/system/"]
Etc --> Ssh["ssh/"]
Var --> Log["log/"]
Var --> Www["www/"]
subgraph sg_apps [应用软件]
Opt["/opt/"]
Snap["/snap/"]
end
Root --> Opt
Root --> Snap
Opt --> OpenList["openlist/"]
subgraph sg_users [用户空间]
Home["/home/"]
RootHome["/root/"]
end
Root --> Home
Root --> RootHome
subgraph sg_virtual [虚拟文件系统]
DirProc["/proc/"]
DirSys["/sys/"]
DirDev["/dev/"]
DirRun["/run/"]
end
Root --> DirProc
Root --> DirSys
Root --> DirDev
Root --> DirRun
subgraph sg_mounts [外部存储]
Mnt["/mnt/"]
Media["/media/"]
end
Root --> Mnt
Root --> Media
1. Core System Directory
bin & sbin (Binaries)
- Uses : Stores executable commands.
- Note:
- bin : Contains basic commands that all users can use, such as
ls,cp,mvetc. - sbin : Contains commands primarily used for system administration; typically, only users with administrator privileges can execute them, such as
reboot,fdisketc.
- bin : Contains basic commands that all users can use, such as
etc (Etcetera/Configuration)
- Uses : Stores system and software configuration files.
- Note : Nginx configuration, user account information, network configuration, and other items are all located here. Modifying files in this directory will directly affect the behavior of the system or services.
- For example: My Nginx configuration file is located at
/etc/nginx/nginx.conf。
- For example: My Nginx configuration file is located at
lib, lib64 (Libraries)
- Uses : Stores system shared libraries.
- Note : Similar to Windows
.dllFiles that provide runtime support for programs in the system.
systemd (System Daemons)
- Key Index:
/etc/systemd/system/ - Uses:Housekeeper Headquarters。
- Note : This is where the “service configuration files” are stored (
.service(file).- When you run
systemctl enable nginxorsystemctl start frpsAt that point, the system actually looks here for the corresponding file. - docker.service.d/ : Custom configuration directories for Docker services (such as proxy settings).
- If you want a program to run automatically at startup, you’ll need to place a configuration file here.
- When you run
boot (Boot Loader)
- Uses : Startup file.
- Note : Store the kernel (
vmlinuz) and the boot loader (GRUB). You generally don’t need to change these unless you’re troubleshooting boot issues on this machine.
2. Where is the software located? (Software Locations)
On Linux, software isn’t centralized the way it is on Windows Program Files...but are scattered across different locations depending on how they are installed. Here is the actual situation on my server:
Native to the System (APT)
Most basic tools (such as Python, Git, and Nginx) are installed via apt install Once installed, they are typically located at:
- Executable file:
/usr/bin/python3->/usr/bin/python3git->/usr/bin/git
- Profile:
/etc/
Note : My Ubuntu 22.04 uses Usr Merge Structure—if you accidentally
/bin/You can also find them there, which is normal (it points to/usr/bin/(soft links).
Ubuntu Exclusives (Snap)
If I use snap install Have installed software (such as certbot), they will live here:
/snap/: The main repository for Snap packages.
Manual Installation (Manual)
Software that I download or compile myself is usually recommended to be placed in:
/opt/: A home for major third-party software (such as/opt/openlist)。/usr/local/bin/: Single-file tools (such asfrpc), so you can run it directly in the terminal from here.
3. User Directory
root
- Uses : The home directory of the system administrator (Root user).
- Note : Unlike regular users,
/homeTable of Contents: The root user’s home directory is located directly under the root directory (/root)。
home
- Uses : The base path of a regular user’s home directory.
- Note : Regular users in the system (such as
admin) The root directory is usually/home/用户名。
4. Variable Data Directory
var (Variable)
- Uses : To store data files that change frequently.
- Note:
- /var/www/html : The default web server document root directory, where my website files are hosted; GitHub Actions uses
rsyncSynchronize build results incrementally to avoid having to re-upload all static resources every time. - /var/log : The directory containing system and application log files, which serves as an important source of information for troubleshooting.
syslog: General system log.nginx/: Nginx Access and Error Logs.auth.log: SSH login logs (essential for troubleshooting).
- /var/www/html : The default web server document root directory, where my website files are hosted; GitHub Actions uses
tmp (Temporary)
- Uses : To store temporary files.
- Note : Temporary data generated while a system or program is running is typically automatically cleared after a restart.
5. Devices and Virtual File Systems
dev (Device)
- Uses : Device file directory.
- Note : In Linux, “everything is a file,” and hardware devices are also mapped as files. For example, a hard drive is typically a
/dev/vda。
proc & sys
- Uses : Virtual File System.
- Note : These directories do not occupy actual disk space; rather, they are in-memory representations of the system state. For example,
/proc/cpuinfoContains real-time information about the CPU.
run (Runtime)
- Uses : Runtime data.
- Note : Stores temporary information during system runtime (such as PID files and socket files), which is lost after a reboot. And
/varThe difference is that the things here are more “fleeting.”
6. Other Common Directories
- mnt & media : Primarily used for temporarily mounting external storage devices (such as USB flash drives and external hard drives).
- opt (Optional) : Used to install large, optional third-party software.
- For example: OpenList (a cloud storage aggregator) is installed on
/opt/openlist/。
- For example: OpenList (a cloud storage aggregator) is installed on
- usr (Unix System Resources) : Contains a large number of user-level tools, libraries, and documentation. Although the name includes “User,” it actually contains system-level shared resources.
7. Hands-On Guide: Configuring Swap Virtual Memory
To improve the server’s stability under heavy load (such as when running AstrBot and NapCat), I manually created 2GB Swap space. This is equivalent to creating an “emergency lane” for the memory modules.
- File Path:
/swapfile(Located in the root directory) - Size:2GB
- Configuration Process:
- Create a File:
sudo fallocate -l 2G /swapfile - Set Permissions:
sudo chmod 600 /swapfile(Read/write access limited to root) - Format:
sudo mkswap /swapfile - Enable:
sudo swapon /swapfile
- Create a File:
- Persisting Configuration:
The following content has been written to
/etc/fstab, to ensure it mounts automatically at startup:/swapfile none swap sw 0 0 - Verification : Use
free -hAs you can see, the “Swap” row is no longer 0B.
Appendix: Hidden Files in the Root Directory
Use ls -a This command displays hidden files in the current directory (using . (Introduction), here is an explanation of common hidden files:
Basic Environment
- .bash_history : Records the history of commands executed by this user on the terminal.
- .bashrc : A Bash shell initialization script used to define aliases, environment variables, and more; it is loaded every time a terminal is opened.
- .profile : An environment configuration file used at login, typically to set the global PATH.
Application Configuration
- .ssh : Store SSH keys and configuration files (such as
authorized_keys), is the key directory for remote login authentication. - .local : Typically contains user-level program configurations or Python
pipInstalled packages (when installed without root privileges). - .pip : The directory containing the configuration files for the Python pip package manager.
- .swas : Data related to the monitoring agent for Alibaba Cloud Lightweight Application Server (SWAS).
- .rpmdb : The database file for the RPM package manager.
Quick Reference for Common Paths (Cheat Sheet)
| Tasks | Path | Common Commands |
|---|---|---|
| Nginx Configuration | /etc/nginx/ | nginx -t |
| Service Management | /etc/systemd/system/ | systemctl status <name> |
| Python3 | /usr/bin/python3 | python3 --version |
| Git | /usr/bin/git | git status |
| View Logs | /var/log/ | tail -f syslog |

