Linux File Hierarchy

Linux File Hierarchy

ยท

7 min read

Table of contents

Introduction

  • Linux File Hierarchy Structure (FHS) : It's like a map that tells us where everything goes in a Linux computer.

  • Maintained by Linux Foundation : The FHS is managed by the Linux Foundation, which makes sure everything stays organized.

  • Root Directory (/) : This is the main place where all files and folders start from, no matter where they are stored.

  • Universal Usage : Most of these directories are used the same way in all UNIX systems, but the FHS gives specific details for Linux systems.

  1. / (root) :

    • The root directory is like the boss of all folders in the computer system.

    • Every file and folder begins from this root directory, which is just a forward slash (/).

    • Only the boss, or root user, can change things directly in this directory.

    • The root directory (/) isn't where the boss keeps personal stuff. The boss's personal folder is /root, which is different from the root directory (/).

  2. /home :

    • Home directories provide personalized spaces for each user on a computer system.

    • Users use their home directories to store their own files, preferences, and other personal data.

    • Each user has their own designated home directory, like /home/chandra or /home/prakash, where they can manage their files independently.

    • Home directories ensure privacy and security by restricting access to individual users' files and settings.

  3. /usr :

    • This level contains read-only user data and most user utilities and applications.

    • It includes binaries, libraries, documentation, and source code for secondary-level programs.

    • Key directories for user programs include :

      • /usr/bin: Holds binary files for user programs like at, awk, cc, less, and scp.

      • /usr/sbin: Contains binary files for system administrators such as atd, cron, sshd, useradd, and userdel.

      • /usr/lib: Stores libraries for programs in /usr/bin and /usr/sbin.

    • User-installed programs are typically found in:

      • /usr/local: This directory houses user-installed programs, typically installed from source code. For example, Apache web server installations go under /usr/local/apache2.
    • Important system resources like Linux kernel sources, header files, and documentation are located in:

      • /usr/src: This directory holds essential items like Linux kernel sources, header files, and documentation.
  4. /etc :

    • These are special files that are specific to the computer they are on and affect the entire system.

    • They hold important settings needed by all programs installed on the computer.

    • This directory also contains scripts that control how programs start and stop when the computer boots up or shuts down.

    • Some examples include /etc/resolv.conf, which stores DNS server settings, and /etc/logrotate.conf, which configures log rotation settings.

  5. /root :

    • This is the personal directory for the root user, who has ultimate control over the entire system.

    • Only the root user has permission to access and modify the contents of this directory.

    • It serves as a private area where sensitive system files and configurations are stored and managed by the root user.

    • It's different from the root directory (/), which is the top-level directory for the entire file system.

  6. /opt :

    • These are extra software programs that you don't necessarily need, but you might want to install for specific tasks or preferences.

    • This directory holds additional applications that come from various source, rather than being included with the operating system.

    • Add-on applications should be installed either directly under the /opt/ directory or within a sub-directory of /opt/. This keeps them organized separately from the core system files.

  7. /lib :

    • This directory holds important libraries that are necessary for the proper functioning of programs located in /bin/ and /sbin/.

    • The libraries stored here are vital for the proper execution of programs found in /bin/ and /sbin/.

    • Library filenames typically start with "ld*" or "lib*.so.*".

  8. /boot :

    • This directory contains essential files required for booting up the operating system.

    • These are files necessary for the boot loader, including kernels and initrd (initial ramdisk) files.

    • Important files found here include kernel initrd, vmlinux, and GRUB files.

    • Bootloader :

      • A bootloader is a small program that loads when you start your computer. It's the first piece of software that runs during the boot process.

      • Its main job is to find and load the operating system into memory. It locates the kernel and essential files needed to start the operating system.

      • The bootloader also handles hardware initialization tasks, ensuring that essential hardware components are properly configured before the operating system takes over.

      • Some bootloaders, such as GRUB (GRand Unified Bootloader), offer a boot menu. This menu enables users to choose between different operating systems or boot options, providing flexibility during startup. GRUB is particularly versatile, allowing users to boot into various operating systems installed on the computer.

      • Apart from GRUB, there are other bootloaders like LILO, Syslinux, rEFInd, and UEFI. Each serves specific needs and preferences, offering various features and functionalities.

  9. /sbin :

    • This directory contains crucial system binaries necessary for system operations and maintenance.

    • Just like the /bin directory, /sbin also stores binary executable files.

    • The commands located here are typically used by system administrators for system maintenance tasks.

    • Some examples of commands found in this directory include fsck, init, shutdown, reboot, fdisk, ifconfig.

  10. /bin :

    • This directory holds essential command binaries that are necessary for system operation, including those required in single-user mode.

    • Many common Linux commands, such as cat, ls, and cp are stored here. These commands are frequently used for various system tasks and operations.

    • Commands located in /bin are accessible to all users of the system. Examples include ps, ping, grep, and cp , which are used by all users for different purposes.

  11. /var :

    • This directory holds changing data files used by the system as it runs.

    • It's where the system keeps files like logs, temporary data, and other things that change a lot while the system is working.

    • Inside /var, you'll find files like system logs, emails waiting to be sent or printed, and temporary files.

    • Both users and system programs use /var to store and access data. It's important to manage this directory properly to keep the system running smoothly.

  12. /mnt :

    • This directory is where users temporarily mount external devices or network locations.

    • It serves as a location for connecting things like USB drives, external hard disks, or network shares to the system.

    • Users often mount devices like USB drives or network folders to /mnt to access their contents.

    • It's a temporary spot for accessing data from external sources. Once the device or location is unmounted, the files are no longer accessible from /mnt.

  13. /media :

    • This directory is where external devices like USB drives and optical discs are automatically mounted by the system.

    • It's a spot where the system automatically connects and shows content from devices like USB drives or CDs when you plug them in.

    • When you plug in a USB drive or insert a CD, the files inside it will show up in /media, allowing you to access them easily.

    • It's a temporary storage area for external devices. Once you remove the device, the files disappear from /media.

  14. /tmp :

    • This directory is used for storing temporary files that are needed while programs are running.

    • It's like a temporary storage area where programs can put files they only need for a short time.

    • Programs might use /tmp to store temporary files while they're working, like when downloading a file or processing data.

    • Files in /tmp are usually deleted automatically when you restart your computer or after a certain amount of time, so it doesn't fill up your storage permanently.

Conclusion

  • Linux arranges files neatly into directory, making it easy to find and manage them.

  • Different directory serve specific jobs, like holding important programs (/bin), keeping changing data (/var), or storing temporary files (/tmp).

  • Users can add their own stuff in places like /usr/local or connect external devices in /mnt and /media, making Linux work just how they want.

  • directories like /home give everyone their own space to keep their files safe, while /boot has what's needed to start up the system smoothly.

  • It's crucial to take care of folders like /var and /tmp to keep the system stable and secure, as they handle important data and temporary files. Regular cleanup and following good practices help keep Linux running well.

Did you find this article valuable?

Support Chandra Prakash Reddy by becoming a sponsor. Any amount is appreciated!

ย