Overview of the Linux Directory Structure

 


LINUX DIRECTORY SYSTEM
LINUX DIRECTORIES EXPLAINED





The Linux directory structure is a hierarchical organization of files and directories, starting from a single root directory denoted by /.


/ (Root Directory)

This is the top-level directory in Linux. Everything on your system starts from here, and all other directories are its subdirectories.

The / directory, known as the root directory, is the highest level in the Linux filesystem hierarchy. It serves as the starting point for all files and directories on the system-every other directory and file is located somewhere beneath.For example, directories like /home, /etc, /bin, and /usr are all subdirectories of /.

Unlike Windows, which uses separate drive letters (like C:, D:), Linux has a single unified directory tree with / at the top.


/bin

This directory contains essential command-line programs and binaries (like ls, cp, mv) that are needed for the system to boot and run in single-user mode. These commands are available to all users.

The /bin directory in Linux stands for "binary" and contains essential executable files, known as binaries, that are required for the basic functioning of the system

Commands stored in /bin include basic utilities such as ls (list files), cp (copy files), mv (move or rename files), mkdir (create directories), rm (remove files or directories).


/sbin

Similar to /bin, but it contains system administration binaries and commands (like reboot, fdisk) that are mostly used by the root (administrator) user.

The /sbin directory in Linux stands for "system binaries." It contains essential executable programs used primarily for system administration, maintenance, and management tasks. The commands found in /sbin are typically needed to boot, repair, or recover the system, and are crucial for the proper functioning of the operating system

Examples of commands you might find in /sbin include ifconfig (network configuration), fdisk (disk partitioning), init (system initialization), shutdown (system shutdown), reboot, fsck (filesystem check), and mkfs (make filesystem)


/etc

This is where system-wide configuration files and settings are stored. For example, network settings, user account information, and service configurations are found here.

The /etc directory in Linux is the central location for system-wide configuration files and directories that control the behavior of the operating system and its installed applications.

The name /etc originally stood for "et cetera," reflecting its early use as a catch-all for miscellaneous system files that didn’t fit elsewhere, but over time it has become specifically associated with configuration files.

Key points about /etc:

  • Purpose: It stores configuration files for the system, network, user accounts, system services, and installed software packages. For example, files like /etc/passwd (user account information), /etc/hosts (local hostname resolution), and /etc/ssh/sshd_config (SSH server configuration) are found here.
  • Scope: These configuration files apply system-wide, affecting all users and services on the machine
  • Administration: System administrators frequently edit files in /etc to change system settings, manage users, configure services, and customize software behavior

/home

Each user on the system has a personal directory under /home (like /home/alice). This is where users store their personal files, documents, and settings.

The home directory in Linux is a personal workspace assigned to each user on the system. It is where users store their personal files, documents, downloads, music, pictures, and configuration settings. Each user has a unique home directory, usually located at /home/username, where "username" is the user's login name

To quickly navigate to your home directory in the terminal, you can use the cd command with no arguments, or use the tilde symbol ~, which is a shortcut for your home directory.

/root

This is the home directory for the root user (the system administrator). It’s separate from the regular users’ home directories for security reasons.

The /root directory in Linux is the home directory for the root user, also known as the superuser or system administrator. While regular users have their personal directories under /home (like /home/alice), the root user’s personal files, configuration settings, and administrative scripts are stored in /root.

/usr

This directory contains user programs, applications, and their related files. Inside, you’ll find subdirectories like /usr/bin (more user commands), /usr/lib (libraries), and /usr/share (shared data).

The /usr directory in Linux stands for "Unix System Resources" and is a key part of the filesystem hierarchy. It contains user-related programs, utilities, libraries, and documentation that are not essential for the basic functioning of the system during boot, but are crucial for running installed software and supporting user operations.

/var

Short for “variable,” this directory contains files that change frequently, such as log files, mail spools, and print queues. For example, system logs are typically found in /var/log.

The /var directory in Linux stands for "variable" and is used to store files that are expected to change frequently as the system runs. Unlike directories such as /usr, which are mostly static and can be mounted as read-only, /var is specifically designed for dynamic data that grows, shrinks, or changes during normal operation

What Goes in /var?

  • Log files: System and application logs are stored in /var/log. These files record events, errors, and other information useful for monitoring and troubleshooting the system.
  • Mail and print spools: Incoming mail for users is kept in /var/mail, and print jobs waiting to be processed are stored in /var/spool.
  • Cache data: Application cache files are kept in /var/cache to speed up repeated operations.
  • Lock files: These are stored in /var/lock and help manage access to resources, ensuring that only one process uses a resource at a time.
  • Temporary files: Files that need to be preserved between reboots but are still temporary in nature are stored in /var/tmp.
  • State information: Persistent data that programs modify as they run, such as databases or package manager metadata, is stored in /var/lib.
  • Other transient files: Any data that is expected to change as the system operates, such as runtime information and queues, is also stored here.

Why is /var Important?

It separates variable data from static data, allowing directories like /usr to be mounted as read-only for security or efficiency.

It helps organize the filesystem by keeping logs, caches, and other changing files in a dedicated place, making system management and backups easier.

Some parts of /var (like logs and locks) are unique to each system and should not be shared between machines, while others (like caches) might be shared in certain setups.


/tmp

This is a space for temporary files created by programs. It’s usually cleared every time the system restarts.

The /tmp directory in Linux is used for storing temporary files that are needed only for a short period of time by the system and user applications. Programs and processes often create files in /tmp to hold intermediate data during their execution-for example, when editing a file, auto-save versions or temporary copies may be placed here.

Key characteristics of /tmp:

  • Short-lived storage: Files in /tmp are meant to be temporary and are typically deleted automatically, either at system reboot or after a certain period of inactivity.
  • System and application use: Both system utilities and user applications use /tmp for temporary storage needs, such as during software installations or while processing data.
  • Access permissions: /tmp is usually world-writable, but with restricted permissions (sticky bit) so that only the file owner or root can delete or modify their own files, enhancing security.
  • Automatic cleanup: Most Linux distributions are configured to clear /tmp at boot or periodically, preventing the accumulation of unnecessary files and freeing up disk space.
  • Not persistent: Data in /tmp does not survive a reboot-if you need temporary files to persist across reboots, /var/tmp should be used instead.
  • Inter-process communication: /tmp is sometimes used for inter-process communication, where different processes exchange data through temporary files. 

 

/dev

This directory contains special files that represent devices attached to the system, such as hard drives (/dev/sda), USB devices, and terminals.

The /dev directory in Linux is a special location that contains device files-also called device nodes or special files-which act as interfaces to the system’s physical hardware and virtual device.Instead of interacting with hardware directly, Linux represents each device (such as hard drives, USB sticks, keyboards, and even virtual devices like random number generators) as a file within /dev. This reflects the Unix philosophy that "everything is a file."

Key Points About /dev:

Device Representation: Each file in /dev corresponds to a specific device or kernel service. For example, /dev/sda represents the first hard drive, /dev/tty represents terminal devices, and /dev/null is a virtual device that discards all data written to it.

Types of Device Files:

  • Character devices: Handle data one character at a time (e.g., keyboards, serial ports).
  • Block devices: Handle data in blocks, suitable for storage devices like hard drives and USB drive
  • Dynamic Management: Modern Linux systems use the udev device manager to dynamically create and remove device files in /dev as hardware is plugged in or removed, ensuring that only relevant device files are present.
  • Not Regular Files: Device files do not store data like normal files. Instead, they serve as gateways for communication between user-space programs and hardware or kernel subsystems.
  • Symbolic Links: Some entries in /dev are symbolic links pointing to other device files or kernel interfaces for compatibility and convenience (e.g., /dev/cdrom might link to /dev/sr0)

In summary:

/dev is a crucial directory that bridges the gap between software and hardware in Linux, allowing user programs to interact with devices in a consistent, file-based manner.


/proc

This is a virtual directory that provides information about running processes and the system itself. It doesn’t contain “real” files but rather files that are generated on the fly by the system.

The /proc directory in Linux is a virtual filesystem that provides a real-time interface to kernel data structures and the current state of the system. Unlike regular directories, /proc does not exist on disk; instead, its contents are dynamically generated by the kernel whenever you access them.

Key Features and Purpose

  • Kernel and Process Information: /proc exposes detailed information about the running kernel, system hardware, and all active processes. For example, files like /proc/cpuinfo provide CPU details, /proc/meminfo shows memory usage, and /proc/uptime displays how long the system has been running.
  • Process Subdirectories: Each running process has its own numbered subdirectory in /proc (e.g., /proc/1234 for process ID 1234). These contain files that reveal information about that specific process, such as its command line, memory usage, open files, and status
  • Dynamic and Up-to-date: The files in /proc are virtual and always reflect the current state of the system. Most have up-to-date timestamps and change as the system changes.
  • Configuration Interface: Some files in /proc, especially under /proc/sys, can be written to in order to adjust kernel parameters at runtime, allowing for on-the-fly system tuning.
  • System Tools: Many system monitoring tools and commands (like ps, top, and free) gather their information by reading data from /proc.

Examples of Useful Files

  1. /proc/cpuinfo: Information about the CPUs.
  2. /proc/meminfo: Details about system memory usage.
  3. /proc/<PID>/status: Status and statistics for a specific process.
  4. /proc/uptime: System uptime.
  5. /proc/sys/: Tunable kernel parameters.

In summary:

/proc is a powerful, virtual directory that lets users and applications inspect and sometimes modify the running state of the Linux kernel, hardware, and processes in real time.


/sys

Another virtual directory, /sys provides information and configuration options for the kernel and connected hardware devices.

The /sys directory in Linux is a virtual filesystem (called sysfs) that provides a structured interface to kernel objects, particularly hardware devices, device drivers, and related kernel subsystems. Like /proc, it is not stored on disk but is dynamically created and managed in memory by the kernel at boot time.


Key Purposes and Features of /sys:

  • Kernel and Hardware Interface: /sys exposes detailed information about the system’s hardware, device drivers, and kernel subsystems. It allows users and applications to view and, in many cases, modify kernel parameters and device settings in real time.
  • Organization: The directory structure of /sys mirrors the relationships between kernel objects, making it clear and organized. For example, you can find directories for devices, buses, drivers, and firmware, each containing relevant attributes and controls.
  • Dynamic and Real-Time: Since /sys is a virtual filesystem, its contents are constantly updated to reflect the current state of the system and its hardware.
  • Writable Interface: Some files in /sys can be written to, allowing administrators and certain applications to adjust kernel parameters or device behavior on the fly.
  • Cleaner Alternative to /proc: /sys was introduced to separate hardware and kernel subsystem information from the more process-focused /proc directory, leading to a cleaner and more maintainable interface.
  • Not Persistent: Because it exists only in RAM, /sys is rebuilt every time the system boots and does not consume disk space.


Example Uses

  1. Viewing hardware information (e.g., /sys/class/net/ for network interfaces)
  2. Adjusting device parameters (e.g., enabling/disabling a device or changing its settings)
  3. Monitoring kernel subsystems and driver status

In summary:

/sys is a virtual, in-memory directory that provides a structured and organized way to access and control kernel objects, hardware devices, and drivers, making it essential for system introspection and dynamic configuration.


/mnt

This is a generic mount point where you can temporarily mount filesystems (like external hard drives or network shares).


/media

This directory is used for automatically mounting removable media like USB drives, CDs, and DVDs.


/opt

Short for “optional,” this directory is used for installing third-party or optional software packages.


/boot

This directory contains files needed to boot the system, such as the Linux kernel and bootloader configuration files.

The /boot directory in Linux contains all the essential files needed for the system’s boot process. This includes the Linux kernel itself, the initial RAM disk image (initrd or initramfs), and bootloader configuration files such as those for GRUB or LILO.

Key contents of /boot:

  • Linux kernel: The core of the operating system, typically named vmlinuz or similar.
  • Initial RAM disk (initrd/initramfs): A temporary filesystem loaded into memory during boot to help the kernel access the real root filesystem.
  • Bootloader files and configuration: Files used by bootloaders (like GRUB or LILO), including configuration files (e.g., grub.cfg), modules, and sometimes splash images
  • System map and backup files: Symbol lookup tables (System.map) and, in some cases, backup copies of boot sectors.

These files are crucial for starting the system. The bootloader, which is the first program loaded by the computer’s firmware, reads its configuration from /boot, loads the kernel and initrd into memory, and then hands control over to the kernel to continue the startup process

In some systems, /boot may be a separate disk partition to ensure the bootloader can reliably access these files, especially on systems with special filesystems or encryption.

In summary:

/boot is a critical directory that stores the kernel, initial RAM disk, and bootloader-related files, all of which are required for the Linux system to boot successfully.


/lib and /lib64

These directories store essential shared libraries needed by programs in /bin and /sbin. On 64-bit systems, /lib64 contains 64-bit libraries.


/run

This directory stores temporary data about the running system, like process IDs and system information. It’s cleared on reboot.


/srv

This directory contains data for services provided by the system, such as web or FTP servers.


/lost+found

This is used by the filesystem to store recovered files after a system crash or disk error. You’ll typically only see this on certain filesystems




Post a Comment

0Comments

Post a Comment (0)