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 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.
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 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.
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.
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 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.
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 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.
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
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.
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.
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).
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.
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.
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 (/).
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 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.
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.
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.
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.
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
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.
โข /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.
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
โข /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.
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.
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...