Linuxopsys
Linuxopsys

@linuxopsys

40 Tweets 6 reads Feb 16, 2023
The Linux filesystem and directory structure explained (detailed thread)๐Ÿงโ†“
The Linux operating system is known for its flexibility and robustness. One of the core components of the Linux operating system is its filesystem. In order to truly understand how Linux works, it is essential to have a clear understanding of its filesystem.
The Linux file system is a method of organizing directories and files in a hierarchical manner. It follows the guidelines laid out by the Filesystem Hierarchy Standard (FHS), but there are still some directories that are not covered by the standard.
If you are new to Linux or are accustomed to Windows, the file system structure of Linux can be strange and perplexing. Instead of the drive letters, such as C:, Linux uses a forward slash (/) as the root directory.
The filesystem is based on a tree-like structure, with the root directory at the top of the tree.
Directories in the Linux filesystem are also referred to as folders (Linux users tend to prefer to use directory instead), and they can contain files, other directories, or both.
Directories can have subdirectories, which in turn can have their own subdirectories, creating a hierarchical structure.
/ - ๐—ง๐—ต๐—ฒ ๐—ฟ๐—ผ๐—ผ๐˜ ๐—ฑ๐—ถ๐—ฟ๐—ฒ๐—ฐ๐˜๐—ผ๐—ฟ๐˜†
The root directory, represented by a forward slash (/), is at the top of the directory structure. The root directory contains the directories and files that comprise the Linux system.
In other words, everything in the Linux filesystem is stored under this directory making it the parent directory of all other directories in the system.
You may have seen some internet jokes that reference "rm -rf /." The rm command in Linux is used to delete files and dirs.
You are simply instructing your system to delete the contents of the root directory forcefully and recursively with rm -rf /.
You end up deleting everything and your Linux system because the root directory contains everything. As a result, use this command with caution.
/๐—ฏ๐—ถ๐—ป - ๐—•๐—ถ๐—ป๐—ฎ๐—ฟ๐—ถ๐—ฒ๐˜€
Short for binary, this directory contains essential system executables also know as binaries and commands that are necessary for the system to function properly. Common utilities and programs such as ls, cp, mv, and rm are located in this directory.
/๐—ฏ๐—ผ๐—ผ๐˜ - ๐—•๐—ผ๐—ผ๐˜ ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
The boot directory contains the kernel and files required for booting the system. This includes the boot loader and other system-related files such as /boot/grub/grub.conf used to modify and configure the gub boot loader.
The contents of the /boot directory may vary depending on the system and configuration.
/๐—ฑ๐—ฒ๐˜ƒ - ๐——๐—ฒ๐˜ƒ๐—ถ๐—ฐ๐—ฒ ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
The dev directory contains device files that are used by the system to communicate with hardware devices. For example, the files /dev/sda and /dev/sdb represent the first and second hard disk drives, respectively.
/๐—ฒ๐˜๐—ฐ - ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
This directory contains configuration files for the system and applications. System-wide settings and configurations are stored in this directory. For example, the file /etc/ passwd contains information about users on the system.
/๐—ต๐—ผ๐—บ๐—ฒ - ๐—จ๐˜€๐—ฒ๐—ฟ ๐—ฝ๐—ฒ๐—ฟ๐˜€๐—ผ๐—ป๐—ฎ๐—น ๐—ฑ๐—ฎ๐˜๐—ฎ
This directory contains the home directories for each user on the system. Each user in Linux has their own subdirectory within /home that only they and the system administrator have access to.
The HOME directory in Linux also stores your personal configuration files, also known as dot files (a dot precedes the name of the file).
These are typically 'hidden,' and in order to see them, you must enable the appropriate option in your file manager or use the terminal command ls with the -a option.
Assume you have two users named foo and bar on your Linux system. They'll each have their own home directories at /home/foo and /home/bar.
/๐—น๐—ถ๐—ฏ - ๐—ฆ๐—ต๐—ฎ๐—ฟ๐—ฒ๐—ฑ ๐—น๐—ถ๐—ฏ๐—ฟ๐—ฎ๐—ฟ๐—ถ๐—ฒ๐˜€
This directory contains shared libraries and modules that are used by the system and applications. These libraries are loaded by the system at runtime when an application needs them. Libraries are easily identified by the extension *.so
In Windows, the equivalent would be a dynamically linked library or DLL in short.
/๐—น๐—ผ๐˜€๐˜+๐—ณ๐—ผ๐˜‚๐—ป๐—ฑ - ๐—Ÿ๐—ผ๐˜€๐˜ ๐—ผ๐—ฟ ๐—ณ๐—ผ๐˜‚๐—ป๐—ฑ
The lost+found directory is used to recover files that have been damaged or lost due to file system errors.
/๐—บ๐—ฒ๐—ฑ๐—ถ๐—ฎ - ๐— ๐—ผ๐˜‚๐—ป๐˜ ๐—ฝ๐—ผ๐—ถ๐—ป๐˜ ๐—ณ๐—ผ๐—ฟ ๐—ฟ๐—ฒ๐—บ๐—ผ๐˜ƒ๐—ฎ๐—ฏ๐—น๐—ฒ ๐—บ๐—ฒ๐—ฑ๐—ถ๐—ฎ
This directory is used to mount removable media, such as CDs, DVDs, and USB drives. When a removable media device is connected to the system, it will be mounted in the /media directory.
/๐—บ๐—ป๐˜ - ๐— ๐—ผ๐˜‚๐—ป๐˜ ๐—ฑ๐—ถ๐—ฟ๐—ฒ๐—ฐ๐˜๐—ผ๐—ฟ๐˜†
Like the previously mentioned directory, the mnt directory is used to temporarily mount file systems and other devices. This directory is typically used for mounting external file systems, such as network file systems (NFS).
/๐—ผ๐—ฝ๐˜ - ๐—ข๐—ฝ๐˜๐—ถ๐—ผ๐—ป๐—ฎ๐—น ๐˜€๐—ผ๐—ณ๐˜๐˜„๐—ฎ๐—ฟ๐—ฒ
The opt directory is used for installing third-party software and applications that are not part of the system's default installation.
/๐—ฝ๐—ฟ๐—ผ๐—ฐ - ๐—ฃ๐—ฟ๐—ผ๐—ฐ๐—ฒ๐˜€๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ธ๐—ฒ๐—ฟ๐—ป๐—ฒ๐—น ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
This directory is a virtual file system that provides information about the system and its processes.
For example, the file /proc/cpuinfo contains information about the system's CPU and the /proc/meminfo file stores information about how much memory your system is using. A number of tools make use of the contents of this directory to obtain runtime system information.
/๐—ฟ๐—ผ๐—ผ๐˜ - ๐—ฅ๐—ผ๐—ผ๐˜ ๐˜‚๐˜€๐—ฒ๐—ฟ'๐˜€ ๐—ต๐—ผ๐—บ๐—ฒ ๐—ฑ๐—ถ๐—ฟ๐—ฒ๐—ฐ๐˜๐—ผ๐—ฟ๐˜†
Like any other user on the Linux system, this directory is the home directory for the root user, the system administrator. It is worth noting that root's home (/root) is not the same as the root directory (/).
/๐—ฟ๐˜‚๐—ป - ๐—ฅ๐˜‚๐—ป๐˜๐—ถ๐—บ๐—ฒ ๐—ฑ๐—ฎ๐˜๐—ฎ
This directory is used to store system runtime data, such as process IDs and lock files. It is typically used for applications that need to store data across reboots.
/๐˜€๐—ฏ๐—ถ๐—ป - ๐—ฆ๐˜†๐˜€๐˜๐—ฒ๐—บ ๐—ฏ๐—ถ๐—ป๐—ฎ๐—ฟ๐—ถ๐—ฒ๐˜€
This directory contains essential system binaries used for system administration tasks, such as system recovery and repair. This directory is analogous to the /bin directory.
The only difference is that it includes binaries that can only be run by root user.
/๐˜€๐—ฟ๐˜ƒ - ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฐ๐—ฒ ๐—ฑ๐—ฎ๐˜๐—ฎ
The srv directory is used for storing data for services provided by the system. For example, if you run a server, such as a web server or FTP server, the files accessed by external users will be stored in this directory.
/๐˜๐—บ๐—ฝ - ๐—ง๐—ฒ๐—บ๐—ฝ๐—ผ๐—ฟ๐—ฎ๐—ฟ๐˜† ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
As the name implies, this directory stores temporary files. Many applications and the system use this directory to store temporary files.
Keep in mind, however, that the contents of the /tmp directories are deleted when your system restarts, so don't save anything important here.
/๐˜‚๐˜€๐—ฟ โ€“ ๐—จ๐˜€๐—ฒ๐—ฟ ๐—ฏ๐—ถ๐—ป๐—ฎ๐—ฟ๐—ถ๐—ฒ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ฝ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ ๐—ฑ๐—ฎ๐˜๐—ฎ
This directory contains user-related files, including user commands, libraries, documentation, and configuration files.
The contents of /usr are not required for the system to boot, but are essential for system functionality.
Here are some examples of directories contained in the /usr directory
โ€ข /usr/bin - contains basic user commands
โ€ข /usr/lib - contains the system libraries
โ€ข /usr/share - contains documentation or files that are shared by all libraries, such as '/usr/share/man', which contains the text of the manpages.
/๐˜ƒ๐—ฎ๐—ฟ - ๐—ฉ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ ๐—ฑ๐—ฎ๐˜๐—ฎ ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
This directory contains variable data files, such as log files, databases, and other files that change frequently.
For example:
โ€ข /var/crash - stores information about crashed processes.
โ€ข /var/log - contains log files for the system as well as other applications.
โ€ข /var/lib - contains dynamic data files/libs.
โ€ข /var/spool - spool data of apps.
โ€ข /var/mail - contains user mailbox files
This information should be sufficient to help you understand the Linux directory structure and how to use it.
That's all! Thank you for getting this far. I hope you find this thread useful.
If you found this thread valuable:
1. Consider following us (@linuxopsys) for more daily threads on Linux, sysadmin and DevOps
2. Like and RT the first tweet so other Linux folks can find it too.

Loading suggestions...