Linuxopsys
Linuxopsys

@linuxopsys

35 Tweets 77 reads Jul 16, 2022
The Linux filesystem and directory structure explained ๐Ÿงโ†“
The Linux Directory Structure is a hierarchical organization system for Linux directories and files. This structure is defined by the Filesystem Hierarchy Standard (FHS)
However, the standard does not yet define some directories in Linux file systems.
If you're new to Linux or switching from Windows, the file system structure of the Linux operating system may appear strange and confusing. C: and other drive letters have been replaced by /.
๐Ÿง / - ๐—ง๐—ต๐—ฒ ๐—ฟ๐—ผ๐—ผ๐˜ ๐—ฑ๐—ถ๐—ฟ๐—ฒ๐—ฐ๐˜๐—ผ๐—ฟ๐˜†
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.
You may have seen some internet jokes that reference "rm -rf /." The rm command in Linux is used to delete files and directories.
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.
๐Ÿง /๐—ฏ๐—ถ๐—ป - ๐—•๐—ถ๐—ป๐—ฎ๐—ฟ๐—ถ๐—ฒ๐˜€
The majority, if not all, of the system's programs or applications, such as cd, cat, ls, and so on, are located in the /bin directory. The vast majority of the programs are binary in nature and are available to all Linux users.
๐Ÿง /๐—ฏ๐—ผ๐—ผ๐˜ - ๐—•๐—ผ๐—ผ๐˜ ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
This is an important folder in Linux because it contains all of the files needed by the operating system to boot, such as the boot loaders, such as the file grub.conf found in the grub directory, as well as the set of vmlinuz, initrd, and kernel related files.
๐Ÿง /๐—ฑ๐—ฒ๐˜ƒ - ๐——๐—ฒ๐˜ƒ๐—ถ๐—ฐ๐—ฒ ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
This is where all of your devices are stored. Your hardware, such as your keyboard, mouse, and printer, can be found here. A disk, for example, would be identified as /dev/sda, and a partition on that disk as /dev/sda1.
๐Ÿง /๐—ฒ๐˜๐—ฐ - ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
The /etc directory contains the system's core configuration files, such as the password file, hostnames, and networking files, which are primarily used by the administrator and services.
๐Ÿง /๐—ต๐—ผ๐—บ๐—ฒ - ๐—จ๐˜€๐—ฒ๐—ฟ ๐—ฝ๐—ฒ๐—ฟ๐˜€๐—ผ๐—ป๐—ฎ๐—น ๐—ฑ๐—ฎ๐˜๐—ฎ
Each user in Linux is assigned a directory that only they and the system administrator have access to. This is where you save personal files, install programs, and save documents.
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.
๐Ÿง /๐—น๐—ถ๐—ฏ - ๐—ฆ๐—ต๐—ฎ๐—ฟ๐—ฒ๐—ฑ ๐—น๐—ถ๐—ฏ๐—ฟ๐—ฎ๐—ฟ๐—ถ๐—ฒ๐˜€
The /lib directory contains the kernel modules and shared library files required for the system to boot. Libraries are easily identified by the extension *.so.
In Windows, the equivalent would be a dynamically linked library or DLL.
๐Ÿง /๐—บ๐—ฒ๐—ฑ๐—ถ๐—ฎ - ๐— ๐—ผ๐˜‚๐—ป๐˜ ๐—ฝ๐—ผ๐—ถ๐—ป๐˜ ๐—ณ๐—ผ๐—ฟ ๐—ฟ๐—ฒ๐—บ๐—ผ๐˜ƒ๐—ฎ๐—ฏ๐—น๐—ฒ ๐—บ๐—ฒ๐—ฑ๐—ถ๐—ฎ
The media directory contains subdirectories in which the system can mount removable media such as CDs and USB keys. This directory provides access to the contents of removable media.
๐Ÿง /๐—บ๐—ป๐˜ - ๐— ๐—ผ๐˜‚๐—ป๐˜ ๐—ฑ๐—ถ๐—ฟ๐—ฒ๐—ฐ๐˜๐—ผ๐—ฟ๐˜†
Like the previously mentioned media folder, the /mnt directory is where you (or the system administrator) manually mount devices or filesystems. The process of making a filesystem available to the operating system is known as mounting.
๐Ÿง /๐—ผ๐—ฝ๐˜ - ๐—ข๐—ฝ๐˜๐—ถ๐—ผ๐—ป๐—ฎ๐—น ๐˜€๐—ผ๐—ณ๐˜๐˜„๐—ฎ๐—ฟ๐—ฒ
The /opt directory in Linux is an optional folder that typically contains manually installed software as well as vendor add-on packages (.i.e not part of the original installation).
๐Ÿง /๐—ฝ๐—ฟ๐—ผ๐—ฐ - ๐—ฃ๐—ฟ๐—ผ๐—ฐ๐—ฒ๐˜€๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ธ๐—ฒ๐—ฟ๐—ป๐—ฒ๐—น ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
The '/proc' directory contains information about currently running processes and kernel parameters. A number of tools obtain runtime system information from the contents of the proc directory.
If you want to check processor information in Linux, for example, go to the file /proc/cpuinfo. Examine the contents of the /proc/meminfo file to see how much memory your Linux system is using.
๐Ÿง /๐—ฟ๐—ผ๐—ผ๐˜ - ๐—ง๐—ต๐—ฒ ๐—ต๐—ผ๐—บ๐—ฒ ๐—ฑ๐—ถ๐—ฟ๐—ฒ๐—ฐ๐˜๐—ผ๐—ฟ๐˜† ๐—ผ๐—ณ ๐˜๐—ต๐—ฒ ๐˜‚๐˜€๐—ฒ๐—ฟ
There is also a /root directory, which serves as the home directory for the root user. As a result, rather than /home/root, root's home is at /root. It is not the same as the root directory (/).
๐Ÿง /๐˜€๐—ฏ๐—ถ๐—ป - ๐—ฆ๐˜†๐˜€๐˜๐—ฒ๐—บ ๐—ฏ๐—ถ๐—ป๐—ฎ๐—ฟ๐—ถ๐—ฒ๐˜€
This is analogous to the /bin directory. The only difference is that it includes binaries that can only be run by root or a sudo user.
๐Ÿง /๐˜๐—บ๐—ฝ - ๐—ง๐—ฒ๐—บ๐—ฝ๐—ผ๐—ฟ๐—ฎ๐—ฟ๐˜† ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
As the name implies, this directory stores temporary files. Many applications use this directory to store temporary files. A directory can also be used 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.
๐Ÿง /๐˜‚๐˜€๐—ฟ โ€“ ๐—จ๐˜€๐—ฒ๐—ฟ ๐—ฏ๐—ถ๐—ป๐—ฎ๐—ฟ๐—ถ๐—ฒ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ฝ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ ๐—ฑ๐—ฎ๐˜๐—ฎ
Here you can find executable files, libraries, source of most of the system programs.
Here are some examples of directories contained in the /usr directory
- /usr/bin - contains basic user commands
- /usr/sbin - contains administrator-specific 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.
๐Ÿง /๐˜ƒ๐—ฎ๐—ฟ - ๐—ฉ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ ๐—ฑ๐—ฎ๐˜๐—ฎ ๐—ณ๐—ถ๐—น๐—ฒ๐˜€
'/var' directory contains variable data that is expected to grow in size (such as system logging files, printer spool directories, mail, and so on).
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/libraries.
โ€“ /var/spool - spool data of applications.
โ€“ /var/mail - contains user mailbox files.
๐Ÿง /๐˜€๐—ฟ๐˜ƒ - ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฐ๐—ฒ ๐—ฑ๐—ฎ๐˜๐—ฎ
This is the service directory, which contains information about the services. If you run a server, such as a web server or FTP server, the files accessed by external users will be stored in /srv/.
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. Toss us a follow for more daily threads on Linux, sysadmin and devops โ†’
@linuxopsys
2. Like and RT the first tweet so other Linux folks can find it too.

Loading suggestions...