Linux, like other operating systems, organizes files and directories in a hierarchical structure. Understanding the Linux file system and directory structure is essential for navigating, managing, and developing on the platform. In this post, we’ll take a closer look at the Linux file system and its key components.
The Linux file system starts with a single root directory. It is the top-most directory in the file hierarchy. It is represented by a forward slash ‘/’. All other directories and files in the file system are located under the root directory., represented by the ‘/’ symbol. Underneath the root directory, there are several standard subdirectories that hold specific types of files. These include:
- /bin: This directory contains binary executables that are essential for the system to function. These are the commands that are commonly used by both users and system processes. Examples include ls, which is used to list the files in a directory, cp which is used to copy files, and mv which is used to move or rename files. These commands are necessary for basic operation of the system and are typically linked to from other directories in the PATH environment variable, so that they can be easily executed from anywhere on the system.
- /boot: The /boot directory is a directory in the Linux file system that contains files necessary for the system to boot. This includes the Linux kernel, the initial RAM disk (initrd), and boot loader configuration files. Additionally, the /boot directory typically contains boot loader configuration files, such as the configuration file for GRUB (GRand Unified Bootloader), which is a popular boot loader for Linux systems. This configuration file tells the boot loader where to find the kernel and initrd and how to configure the boot process.
- /etc: This directory contains configuration files for various system programs and services. These files are typically text files that can be edited by the system administrator to configure the behavior of the associated program or service. Examples include /etc/passwd, which contains user account information, and /etc/fstab, which contains information about file systems that are automatically mounted at boot time. The /etc directory is used to store configuration information that is specific to the system or local to the machine.
- /dev: This directory contains device files that represent various hardware devices on the system. These files are special files that allow programs to interact with hardware devices such as disk drives, terminals, and network interfaces. Device files are typically created automatically by the system and can be accessed just like regular files. However, instead of reading and writing data to a file, reading and writing operations on a device file are translated into operations on the corresponding hardware device.
- /home: The home directory contains the home directories of users. Each user on the system typically has their own home directory under /home, where they can store their personal files and configurations. The home directory is usually where a user is placed when they first log in to the system, and it is where the user’s environment and settings are stored.
- /lib: This directory contains libraries needed to run programs in the /bin and /sbin directories. Libraries are collections of pre-written code that can be used by programs to perform common tasks, such as reading and writing files, connecting to networks, and interacting with hardware devices. These libraries are shared among multiple programs and can help to reduce the size of the executables and make the system more efficient.
- /media: This directory contains mount points for removable media such as USB drives, CD-ROMs, and external hard drives. When a removable media is inserted or connected to the system, it is typically automatically mounted at a location under /media.
- /mnt: This directory is similar to /media but is intended for temporary mount points for file systems. This directory is typically used by system administrators to mount file systems temporarily for maintenance or backup purposes.
- /opt: This directory is typically used to store third-party software that is not part of the standard system distribution. The name “opt” stands for “optional” and it is intended to be a location for add-on software that is not included with the standard system distribution.
- /root: This directory is the home directory for the superuser (also known as the “root” user). The superuser is the most privileged user on a Linux system and has the ability to perform any action on the system. The /root directory is similar to the home directories of other users, but it is typically only accessible by the superuser and system processes.
- /run: This directory contains runtime data for system services and applications. The /run directory is intended to be used for storing transient data that is needed during the current session, but that does not need to be preserved across system reboots. This directory contains files such as socket, pid and other temporary files.
- /proc: It is a virtual file system that contains information about the system’s processes. The proc file system is not a real file system that stores files on a disk. Instead, it provides a way for processes to read information about other processes and the system itself. It provides a way for system administrators and other users to see the status of various processes running on the system.
- /sys: is a virtual file system that contains information about the system’s hardware. The sys file system is similar to proc in that it is not a real file system that stores files on a disk. Instead, it provides a way for processes to read information about the system’s hardware, such as the status of various devices, and to configure the hardware.
- /sbin: This directory contains system binary executables that are used for system maintenance and administration. These executables are typically only used by the system administrator or superuser, and include commands such as reboot, which is used to reboot the system, fdisk which is used to manipulate disk partitions, and iptables which is used to configure the system’s firewall. These commands are not necessary for normal operation of the system and are not typically included in the PATH environment variable.
- /var: contains variable data such as log files, temporary files, and spool files. These files are created and modified during the normal operation of the system and can include things like log files from system services, email queues, and print spools.
- /usr: It contains user related data such as binaries, libraries, documentation, and source code. This directory is typically used to store files that are not necessary for the system to boot and operate, but that are used by users and applications. The /usr directory is often used to store architecture-independent files, such as documentation, libraries, and user home directories. It contains subdirectories like /usr/bin, which contains binary executables for user applications, /usr/lib, which contains libraries for user applications, and /usr/share, which contains architecture-independent data such as documentation, icons, and localization files.
- /tmp: This directory is used for temporary files that are deleted when the system is rebooted.
It’s important to note that the above directories and their contents are not exclusive to all Linux distributions, some may have different directory structure or different naming.
In addition to the standard subdirectories, users can also create their own directories and files within the file system. When working with files and directories in Linux, it’s important to have a good understanding of the file system hierarchy and the standard directories. This will help you navigate, manage, and develop on the platform more effectively. Each file and directory have associated permissions that determine who can read, write, or execute the file. To read the File permission in detail please click here. It explains the file permission in details.
Ref: Filesystem Hierarchy Standard – Wikipedia