Linux Root Structure

Let's learn the Basic Root Structure for the Linux system to learn basic linux

12/7/20242 min read

Let’s learn the Basic Root Structure for the Linux system

/ — (Root) — The base of the file system. All directories, files, and devices stem from this root. Store admin-specific scripts, configuration files, and sensitive information. Example: A script to reset system user passwords stored in /root/reset_passwords.sh

/bin — Binaries (commands) needed during boot or single-user mode. Default system commands like ls, cp, cat, echo, etc., live here.
Example: Running ls to list files works because its binary is in /bin. In Linux, “binaries” refer to compiled executable files that the system can run directly.

A compiled executable file is a program that has been translated from human-readable source code (written in programming languages like C, C++, or Java) into machine-readable instructions (binary code) that a computer’s processor can execute directly.

/sbin — System binaries used for administrative tasks for root user commands like ifconfig, iptables, fsck, and reboot.

/boot — Files required for booting the system, including Linux kernel.Stores the Linux kernel, bootloader (like GRUB) configuration, and initial RAM disk.
Example: Updating the kernel (vmlinuz) or editing bootloader settings in /boot/grub/grub.cfg.

/dev — Device files representing hardware and virtual devices. Access devices like hard drives (/dev/sda), USB drives (/dev/sdb), or terminals (/dev/tty).
Example: Mounting a USB device (mount /dev/sdb1 /mnt/usb).

/etc — System-wide configuration files. Configuring network, users, applications, and services.
Examples:
passwd: User authentication data.
hosts: Map hostnames to IP addresses.
nginx.conf: Configuration for the NGINX web server.

/home — Home directories for regular users. Example: /home/vasanth
Each user gets their own subdirectory (/home/username) to store personal files and settings.
Example: Storing user files, like /home/vasanth/file.docx.

/lib — Shared libraries for binaries in /bin and /sbin.
Example: Running ls relies on libraries like libc.so from /lib.

/media -Mount points for removable media like USB drives, CDs, or DVDs.
Automatically mount USB drives or SD cards when inserted.
Example: Accessing files on a USB drive mounted at /media/usb.

/mnt -Temporary mount points for manually mounted file systems.
Manually mounting remote filesystems or temporary storage.
Example: mount /dev/sdb1 /mnt/temp for temporary access.

/opt — Optional software not managed by the system’s package manager
Optional software is installed manually, without using Package managers like apt,yum tools.
Install third-party applications or custom software. Example: Installing a custom version of Apache under /opt/apache.

/proc — Virtual filesystem providing system and process information.
Example:
Check CPU info: cat /proc/cpuinfo.

/run — The /run directory is a temporary filesystem used to store runtime data for processes that have started since the system booted. It replaces older directories like /var/run and /var/lock.
Example: Systemd and other init systems store session and state information here. Example: /run/systemd/.

/srv -The /srv directory is used to store data served by the system’s services. This includes files and directories related to web servers, FTP servers, or other server-related activities.
Example:
A web server like Apache or NGINX might serve files from /srv/www.
Example: /srv/www/mywebsite.com/public_html/index.html.
Files
shared via FTP might be stored in /srv/ftp.

/sys — sysfs is a virtual filesystem in Linux that provides a structured way to access kernel devices, modules, and settings.

Monitoring Hardware Information — Checking CPU Topology and Configuration. Path: /sys/devices/system/cpu/

Example: Find the number of CPUs or cores available.
cat /sys/devices/system/cpu/present

/tmp — Temporary files, Cleared on reboot. Store temporary data required by applications during execution.

/usr — User applications and utilities. Non-essential commands and libraries.

Examples:
/usr/bin: User programs like vim, nano, python.
/usr/sbin: Non-critical system binaries like apachectl.
/usr/lib: Libraries for programs in /usr/bin.
/usr/local — Locally installed software and utilities.

/var — Variable data files like logs & caches.
Examples: Logs: /var/log/syslog, /var/log/nginx/access.log; Mail queues: /var/spool/mail.