![]() |
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)
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
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
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
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
/root
/usr
/var
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.
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
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
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
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
- /proc/cpuinfo: Information about the CPUs.
- /proc/meminfo: Details about system memory usage.
- /proc/<PID>/status: Status and statistics for a specific process.
- /proc/uptime: System uptime.
- /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
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
- Viewing hardware information (e.g., /sys/class/net/ for network interfaces)
- Adjusting device parameters (e.g., enabling/disabling a device or changing its settings)
- 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.
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