Linux's directories are the backbone of the operating system, providing a systematic and organized way to manage files and programs. Without them, navigating and using Linux would be a daunting task.
In this article, we'll explore the different directories that constitute the Linux file system and how they contribute to the functioning of the OS.
Whether you're a beginner or an experienced developer, understanding the importance of Linux directories is essential for unlocking the full potential of this powerful OS.
Root directory - /
Everything, all the files and directories, on Linux are located under root
represented by /
. If you look at the directory structure, youâll realize that it is similar to a plantâs root.
Since all other directories or files are descended from root, the absolute path of any file is traversed through root. For example, if you have a file in /home/user/images
, you can guess that the directory structure goes from:
root
> home > user > images.
You may have come across some jokes on the internet that mention
rm -rf /
With rm
-rf /
, you ask your system to forcefully and recursively delete the contents of the root directory. Since root directory has everything underneath, you end up deleting everything and your Linux system just vanishes (theoretically).Most Linux distribution wonât run this command unless you provide
âno-preserve-root
.Binaries - /bin
The /bin
directly contains the executable files of many basic shell commands like ls, cp, cd, rm etc. Most of the programs are in binary format here and accessible by all the users in the Linux system.
System binaries - /sbin
This is similar to the /bin
directory. The only difference is that is contains the binaries that can only be run by root or a sudo user. You can think of the s
in sbin
as super or sudo.
Configuration files - /etc
The /etc
directory contains the core configuration files of the system, use primarily by the administrator and services, such as the password file and networking files.
If you need to make changes in system configuration (for example, changing the hostname), this is where youâll find the respective files.
Device files - /dev
This directory only contains special files, including those relating to the devices. These are virtual files, not physically on the disk.
Some interesting examples of these files are:
/dev/null
can be sent to destroy any file or string/dev/zero
contains an infinite sequence of 0/dev/random
contains an infinite sequence of random values
Variable data files - /var
Var, short for variable
, is where programs store runtime information like system logging, user tracking, caches, and other files that system programs create and manage.
The files stored here are not cleaned automatically, and hence it provides a good place for system administrators to look for information about their system behavior.
Boot files - /boot
The /boot
directory is one of the most vital directories in a Linux system. As the name infers, the boot directory contains Linux boot files such as the bootloader, the kernel, and its associated files. Files such as vmlinuz represent the compressed image of the Linux kernel.
Process and kernel files - /proc
The /proc
directory contains the information about currently running processes and kernel parameters. The content of the proc directory is used by a number of tools to get runtime system information.
For example, if you want to check memory usage of your Linux system, just look at the content of /proc/meminfo
file.
Optional software - /opt
Normally, the /opt
directory is used for installing/storing the files of third-party applications that are not available from the distributionâs official repository.
For example, when you install applications such as Skype, Discord, Spotify, and Java, to mention a few, they get stored in the /opt
directory.
The normal practice is to keep the third-party software code in opt and then link the binary file in the /bin
directory so that all the users can run it.
The home directory of the root - /root
The /root
directory works as the home directory of the root user. So instead of /home/root, the home of root is located at /root. Do not confuse it with the root directory (/).
User binaries and program data - /usr
in /usr
go all the executable files, libraries, source of most of the system programs. For this reason, most of the files contained in this folder are read-only (for the normal user)
/usr/bin
contains basic user commands/usr/sbin
contains additional commands for the administrator/usr/lib
contains the system libraries/usr/share
contains documentation or common to all libraries, for example/usr/share/man
contains the text of the man page
User personal data - /home
Home directory contains personal directories for the users. The home directory contains the user data and user-specific configuration files. As a user, youâll put your personal files, notes, programs etc in your home directory.
When you create a user on your Linux system, itâs a general practice to create a home directory for the user. Suppose your Linux system has two users, Kevin and Arsene. Theyâll have a home directory of their own at locations /home/kevin
and /home/arsene
.
Do note that Kevin wonât have access to /home/arsene and vice versa. That makes sense because only the user should have access to his/her home.
Shared librairies - /lib
Libraries are basically codes that can be used by the executable binaries. The /lib
directory holds the libraries needed by the binaries in /bin
and /sbin
directories.
Libraries needed by the binaries in the /usr/bin
and /usr/sbin
are located in the directory /usr/lib
.
Temporary files - /tmp
As the name suggests, this directory holds temporary files. Many applications use this directory to store temporary files. You can also use this  directory to store temporary files.
Note that the contains of the /tmp
directories are deleted when your system restarts. Some Linux system also delete files old files automatically so donâ store anything important here.
Mount point for removable media - /media
When you connect a removable media such as USB disk, SD card or DVD, a directory is automatically created under the /media
directory for them. You can access the content of the removable media from this directory.
Mount directory - /mnt
This is similar to the /media directory but instead of automatically mounting the removable media, /mnt
is used by system administrators to manually mount a filesystem.
Service data - /srv
The /srv
directory contains data for services provided by the system. For example, if you run a HTTP server, itâs a good practice to store the website data in the /srv directory.
Lost and Found files - /lost+found
The /lost+found
directory is installed during the installation of Linux, useful for recovering files that may be broken due to unexpected shut-down.
I hope you enjoyed reading this, and I'm curious to hear if this tutorial helped you. Please let me know your thoughts below in the comments. Don't forget to subscribe to my newsletter to avoid missing my upcoming blog posts.
You can also find me here LinkedIn ⢠Twitter ⢠GitHub or Medium
Exploring important files and their usability
Linux is a complex system that requires a more complex and efficient way to start, stop, maintain and reboot a system, unlike Windows.
There is a well-defined configuration file, binaries, man pages, info files, etc. for every process on Linux.
In addition to the major directories, here is a list of some of the prominent files and directories and their uses.
â˘
/dev/null
A pseudo-device, that doesnât exist. Sometimes garbage output is redirected to /dev/null, so that it gets lost, forever.â˘
/etc/hosts
This is a configuration file that maps system hostnames to their corresponding IP addresses.â˘
/etc/passwd
A file that contains the system userâs information such as the username, UID, GID, and login shell among others.â˘
/etc/profile
Contains Linux system-wide environment and other startup scripts.â˘
/etc/profile.d
Application script, executed after login.â˘
/usr/bin
Normal user executable commands.Conclusion
Understanding how the Linux system works is not merely a technical endeavor; it is an investment in personal growth, empowerment, and security.
As Linux continues to shape our digital landscape, the importance of understanding its inner workings cannot be overstated. Embrace the journey of exploration, and let the world of Linux unfold its vast possibilities before you.