Navigating the Linux Directory Structure: A Roadmap to Understanding
Gauri Yadav
Docker Captain @Docker.Inc ? Google Program Mentor ? Cloud Intern @Gavedu ? DevSecOps Culture ? Kubernetes ? 3x Azure Certified ? Technical Speaker ??
In the realm of Linux, the concept holds true that everything can be viewed as a file, including directories, commonly referred to as folders.
In this article, we will delve into the organizational structure of files and directories within the Linux Operating System.
The standard directory structure adhered to by most Linux distributions is known as the Filesystem Hierarchy Standard (FHS), a set of guidelines maintained by the Linux Foundation.
Personally, I find great satisfaction in navigating and managing Linux and Unix-like servers through the command line interface (CLI). In this discussion, I will leverage my Rhel9 server's terminal to elucidate the intricacies of the directory structure.
/ (root) directory -->
The directory denoted by a forward slash ('/') is referred to as the "root" directory, serving as the foundation for the file system hierarchy. It's important to clarify that the term "root" in this context doesn't relate to the root superuser account. In Linux, all elements, including partitions, are situated beneath the root directory. It's worth noting that only the root user possesses the privilege to execute write operations within this directory.
utilized the 'tree' command to display the contents of a directory in a tree-like structure, covering all levels recursively.
To acquire the 'tree' tool, you can install it using the command below.
Furthermore, if you wish to list only the first level of the directory tree, commencing from the root directory '/', you can use the following command.
# apt install tree -y
# tree -L 1 /
/bin directory -->
Within the '/bin' directory, you'll find a collection of executable files. Among these, many are essential for various purposes, such as maintenance tasks during single-user mode or for file system repairs. Examples of such vital commands include 'ls,' 'cp,' 'cat,' 'echo,' 'df,' and more.
/dev directory -->
The '/dev' directory houses device files corresponding to the hardware components within your system, such as 'cdrom,' 'cpu,' terminal devices, USB, and more. In Linux, the intriguing aspect is that the system treats these devices as if they were regular files, enabling you to read from and write to them just like you would with standard files. It's important to note that these are not device drivers but rather representations of the devices as files within the Linux file system.
/boot directory -->
In this location, you'll find all the essential files needed for the system's boot process. These files encompass the static bootloader, the kernel executable, and various configuration files.
/etc directory -->
The '/etc' directory houses the fundamental configuration files that are vital for the system's operation. These files, primarily in plain text format, are essential for the proper functioning of various programs. Typically, it's System Administrators and DevOps professionals who handle these files. They encompass a wide range of configurations, such as usernames, passwords, network settings, application-specific configurations, as well as system startup and shutdown scripts.
/home directory -->
Within this directory, you'll discover home directories allocated to individual users for storing their personal files. Whenever a new user account is created, a corresponding directory bearing their username is automatically generated within the home directory to provide them with a dedicated storage space.
root user's home directory is /root.
/lib and lib64 directories -->
These directories house shared library files crucial for booting the system, functioning much like DLLs on Windows.
To clarify, '/lib' accommodates 32-bit compatibility libraries, while '/lib64' hosts 64-bit libraries.
/media directory -->
Any external storage such as media/cdrom when plugged in will be automatically mounted under /media directory.
/mnt directory -->
This directory serves as a location where system administrators can mount regular filesystems like NFS, although it's not a frequently utilized practice in modern times.
/opt directory -->
This directory contains any third-party applications available from individual vendors. It is recommended to install third-party applications under /opt or /opt subdirectory.
领英推荐
/proc directory -->
This directory stores data related to system processes identified by a specific process ID (PID). It's commonly referred to as a virtual or pseudo filesystem, as it contains textual information about various system resources, including CPU and memory. Files and directories within this directory are generated dynamically as the system starts or undergoes changes.
/root directory -->
Home directory for root user.
/run directory -->
This directory contains system executables used for system administration for maintenance. It is similar to /bin, but it contains only the superuser-required applications. For e.g. fdisk, fsck, reboot, shutdown, iptables.
/sys directory -->
This is another virtual directory similar to /proc and /dev containing information from devices connected to your computer. It allows modification of the devices connected to the system.
/tmp directory -->
It contains temporary files. Many applications keep their temporary files here which contain data that an application might not need right now but may need later on. These files will be kept until the next boot or application restart.
/usr directory -->
This directory contains applications, libraries, docs, icons, images and other files which needs to be shared by applications and services. It is basically shareable, read-only data.
There are further sub-directories within /usr directory. /usr/bin :- Non-essential command binaries (not needed in single-user mode); for all users.
- /usr/include: This directory holds standard include files.
- /usr/lib: It contains libraries that are used by the binaries in '/usr/bin' and '/usr/sbin.'
- /usr/lib<qual>: These are alternative-format libraries. For instance, '/usr/lib32' might be used for 32-bit libraries on a 64-bit system (optional).
- /usr/local: Within this directory, you'll find host-specific local data. Typically, it comprises subdirectories like 'bin,' 'lib,' and 'share.'
- /usr/sbin: This directory stores non-essential system binaries, such as daemons for various network services.
- /usr/share: It holds architecture-independent, shared data.
- /usr/src: This directory is dedicated to source code, including elements like the kernel source code along with its header files.
/var directory -->
This directory contains variable files such as log files, lock, mail, cache and temp files that change constantly when the system is running and are expected to grow further.
There are further sub-directories within /var directory
- /var/cache: This directory is designated for application cache data.
- /var/lib: It holds state information, which comprises persistent data that programs modify as they run. This can include databases, packaging system metadata, and more.
- /var/lock: Within this directory, you'll find lock files. These files keep track of resources that are currently in use.
- /var/log: It's the home for various log files, which record different system activities.
- /var/mail: Mailbox files reside here. In some distributions, you might also find these files in the deprecated /var/spool/mail directory.
- /var/opt: This directory contains variable data from add-on packages, typically stored in /opt.
- /var/run: Previously used for run-time variable data describing the system since it was booted, this directory has been replaced by /run in FHS 3.0.
- /var/spool: It acts as a spool for tasks that are awaiting processing, such as print queues and outgoing mail queues.
- /var/tmp: Temporary files meant to be preserved between reboots are stored in this directory.
So, whether you're a seasoned Linux pro or just beginning your Linux journey, take a moment to appreciate the elegance of the Linux directory structure. It's the foundation of a world where you have the power to control and customize your computing environment.
With that, happy Linux learning, and may your Linux directory explorations be filled with joy and success!
Senior Enterprise Technology Engineer | Aspiring Collaborative Leader ?? | Growth Enthusiast ?? | Azure, AWS, Kubernetes (CKA), Terraform Certified ?
1 年Very useful. Thanks for sharing Gauri yadav
Computer Engineer | Cybersecurity Enthusiast | Linux | Networking | Cloud Computing
1 年Great and simple explanation. Easy to understand. Waiting for more content Gauri yadav ??