Detailed Explanation of the /usr Directory in Linux

πŸ“‚ Linux Subdirectory <strong><span>/usr</span></strong> Directory Detailed Explanation

πŸ“Œ I. Overview

<span><span>/usr</span></span> is one of the most important directories in the Linux file system, which stands for “Unix System Resources”. It is used to store user programs, system tools, library files, documentation, shared resources, etc.. Originally designed as a read-only directory, it can be shared across multiple systems via network or local mounts.

πŸ“ II. Structure and Content of the /usr Directory

/usr/β”œβ”€β”€ bin        # Binary files for user commands (e.g., common commands like ls, cp, grep, etc.)β”œβ”€β”€ sbin       # Binary files for system administrators (e.g., ifconfig, iptables, etc.)β”œβ”€β”€ lib        # Library files and kernel modules (for the current architecture)β”œβ”€β”€ lib64      # Library files for 64-bit systems (used by some systems)β”œβ”€β”€ include    # Header files for C/C++ programming (e.g., standard library headers)β”œβ”€β”€ local      # Locally installed software and resources (distinct from system package management)β”œβ”€β”€ share      # Architecture-independent shared data files (e.g., documentation, fonts, themes)β”œβ”€β”€ src        # Optional directory for storing system source codeβ”œβ”€β”€ man        # Manual page filesβ”œβ”€β”€ games      # Games and entertainment software (now rarely used)└── tmp        # Temporary file directory for program use

πŸ” III. Detailed Explanation of Common Subdirectories

πŸ“ 3.1 /usr/bin

  • Stores binary executable files that users can use.

  • Contains a large number of user commands provided by the system:<span><span>ls</span></span>, <span><span>cp</span></span>, <span><span>grep</span></span>, <span><span>bash</span></span>, etc.

  • Users can execute without special permissions.

πŸ“ 3.2 /usr/sbin

  • Stores binary files used by system administrators.

  • Includes:<span><span>ifconfig</span></span>, <span><span>iptables</span></span>, <span><span>useradd</span></span>, <span><span>visudo</span></span>, etc.

  • Ordinary users typically cannot access or execute, only administrators or those using <span><span>sudo</span></span> can run.

πŸ“ 3.3 /usr/lib and /usr/lib64

  • Stores library files and kernel modules.

  • <span><span>/usr/lib</span></span> is for 32-bit libraries or common libraries, <span><span>/usr/lib64</span></span> is for libraries for 64-bit systems.

  • Includes:<span><span>libc.so</span></span>, <span><span>libm.so</span></span>, etc., standard C libraries and third-party libraries.

πŸ“ 3.4 /usr/include

  • Used to store header files for C and C++ languages.

  • Developers use <span><span>#include</span></span> to include file paths when writing programs.

  • Includes:<span><span>stdio.h</span></span>, <span><span>stdlib.h</span></span>, <span><span>unistd.h</span></span>, etc.

πŸ“ 3.5 /usr/local

  • Used for installing locally compiled or third-party programs.

  • Not controlled by system package managers (like <span><span>apt</span></span>, <span><span>yum</span></span>), users can modify freely.

  • The directory structure is similar to <span><span>/usr</span></span>, but specifically for manually installed software:

/usr/local/β”œβ”€β”€ bin        # User binary filesβ”œβ”€β”€ sbin       # Administrator binary filesβ”œβ”€β”€ lib        # Library filesβ”œβ”€β”€ include    # Header filesβ”œβ”€β”€ share      # Architecture-independent data└── src        # Source code

πŸ“ 3.6 /usr/share

  • Stores architecture-independent shared data files.

  • Includes: manuals, fonts, icons, internationalization resources, documentation, etc.

  • For detailed content, refer to:<span><span>/usr/share Detailed Explanation</span></span>.

πŸ“ 3.7 /usr/src

  • Stores Linux kernel source code and third-party source code.

  • Commonly found in environments for developing or compiling custom kernels.

  • Example:<span><span>/usr/src/linux-headers-5.10.0-13/</span></span>.

πŸ“ 3.8 /usr/man or /usr/share/man

  • Stores manual page files, divided into multiple sections.

  • Access method:<span><span>man <command></span></span>, such as <span><span>man ls</span></span>.

πŸ“ 3.9 /usr/games

  • Traditionally used to store binary files for games or entertainment software.

  • Rarely used in modern systems, usually an empty directory.

πŸ“ 3.10 /usr/tmp

  • A optional temporary directory, similar to <span><span>/tmp</span></span>.

  • Almost unused in modern systems, usually an empty directory.

πŸ“Š IV. Differences Between /usr and Other Directories

Directory Purpose Can be mounted as read-only
<span><span>/bin</span></span> Essential user commands, used for system boot and recovery. ❌
<span><span>/sbin</span></span> Essential administrator commands, used for system maintenance. ❌
<span><span>/lib</span></span> Essential library files, used during system boot. ❌
<span><span>/usr</span></span> A large collection of standard user programs and resources. βœ… (usually read-only)
<span><span>/usr/local</span></span> Locally installed applications and resources. βœ… (usually read-only)
<span><span>/var</span></span> Variable data files (logs, caches, lock files, etc.). ❌

πŸ› οΈ V. Usage Examples

5.1 View <span><strong><span>/usr/bin</span></strong></span> all programs

ls /usr/bin

5.2 View <span><strong><span>/usr/lib</span></strong></span> library files

ls /usr/lib | grep lib

5.3 Install custom software to <span><strong><span>/usr/local</span></strong></span>

./configure --prefix=/usr/localmake
sudo make install

5.4 View manual page

man ls

βœ… VI. Summary

  • <span><span>/usr</span></span> is one of the most important directories in the Linux system, containing user programs, library files, shared resources, etc.

  • Distinguished from <span><span>/bin</span></span>, <span><span>/sbin</span></span>, <span><span>/lib</span></span> and other core directories, <span><span>/usr</span></span> data can be mounted as a separate partition or read-only directory.

  • It is recommended to place locally custom-installed software in the <span><span>/usr/local</span></span> directory to avoid conflicts with the system package manager.

Leave a Comment