Ultimate Guide to Linux Directories: Unraveling the File System Hierarchy
Delve into the intricate web of Linux directories and ace your Linux Interviews
Directory Structure in Windows
I am pretty sure most of us (even the non-techies) have seen a Windows File Directory on our personal computers (The main page when you click on Files)
Here, in this example, the Windows(C:) and New Volume (D:) are two separate drives that have their own separate folders and are isolated from each other. That is, there is no 'parent' for these two drives that can hold them/ contain them together in one space/ directory.
To visualize this properly, think of Window (C:) and New Volume (D:) as two families from the same hometown. These two families might be connected indirectly ( they are from the same hometown ) but there is no direct link that binds them together. When you look at them separately, they are individual entities that have their own children and these children can have their own children - just like a family tree.
In technical terms, the Windows Directory system can have multiple root nodes with multiple children. All of these root nodes can have separate functions that are unique to them. ( Your Operating System data is stored in your C drive. All your games might be stored in your D drive, your work-related data can be stored in E drive, and so on )
Your game files will never interact with your Windows files stored in C drive.
Directory Structure in Linux
Now Linux directory structure is a little different from that of Windows. Linux follows the philosophy of “Everything is a file”, which means, everything that is on your Linux Operating System must be stored in a file.
What Linux follows is the concept of having only one root directory root (/)
in which all files are stored, both System and User. If we consider the example of 2 families from above, we can think of the two family’s root node ( the parents ) being siblings from one big joint family, settling elsewhere to to start their own family. These 2 families ( different directories of Linux ) might be inherently different from each other but are directly connected through the main family ( root /
).
The root (/)
is the parent node inside whom everything that consists of the Linux system is stored in the form of child nodes ( directories ).
/
). This also includes things that are not inherently a file or things that are not supposed to be treated as a file./proc
directory as virtual files. These files convey a great deal of information about your kernel and other system processes running on your system. A lot of it is read-only but a lot of it is also writable. Network and Unix Domain sockets can also be found and manipulated through the Linux File System. You can also access and manipulate your drivers through /dev
.Note: Windows with each rolling version is getting closer to giving the user with greater low-level system access but is still lacking and fails to take this concept to the same level as Linux.
File Directory in Linux
All the directories of Linux are contained inside the root directory (/)
.
You can think of Root as the mother/father of all directories stored in the system. Every directory present inside your system is stored inside the Root Directory.
pwd
shows you your current directory, above shows we are in the root directory of our Linux System.
ls -l
lists all folders and files inside your ‘present working directory’
Now let's dive deeper into what each directory holds.
/bin
- Stands for Binaries. This directory stores all binaries necessary in the very early boot stage or ones that you need to have available during single-user booting. Ex - cat, cp, ls/sbin
- Stands for System Binaries. This holds binaries just like/bin
but the binaries stored here are essential system binaries that are powerful enough to affect the system as a whole. Root permission is required to access these binaries. Ex - init, fdisk/boot
- this directory holds all the files that are required for booting. This file contains the bootloader files./dev
- this directory contains all the device files. Now, these device files are not your normal files rather they are ‘special files’ (yes, that’s what they are called). These files provide access to your peripheral devices such as keyboard, mouse, etc. They also store your hard disk partitions./etc
- This directory basically stores all of your system configuration files. Any program that you install in your Linux, is stored in the/etc
directory./home
- This directory is your home directory in which all your system users are stored. This is your default directory!user folder in
/home
directoryuser files inside the user - vishal directory
/lib
- This directory contains shared ( and helpful) libraries needed to run commands inside our root filesystem. These files will be needed by an application, a process, or a command to properly execute themselves. Required by binaries in/bin
and/sbin
./lib64
- This can either be/lib64
or/lib32
depending on your system hardware. Think of this as an alternate shared library that stores variations of/lib
to support more than one binary format. Used for systems that support multiple binary formats, but require the library of the same name.💡A more intuitive way to differentiate between/lib
and/lib64
would be to think of/lib
as your primary language and/lib64
as your secondary language. You perform your everyday important tasks using your primary language, the/lib
but you are also capable of understanding things in your secondary language/lib64
, which at times is useful when talking to someone whose secondary language is their primary language./lost+found
-This directory stores files that have become either obsolete or have been lost/ corrupted in a disk operation. In simple terms, it is a dustbin that can be used to recover deleted, corrupted, or lost data./media
- This directory contains sub-directories which are used by removable media for mounting, like floppy disks, USB, CDRoms, etc/mnt
- This directory is usually used by a system admin to temporarily mount a filesystem when needed.❓Isn’t/mnt
and/media
the same? Both are used for mounting?💡Well, both might seem the same but they are structurally different./mnt
is manually mounted and/media
is automatically mounted into the system. If you insert into removable device into your computer, it is automatically mounted into the/media
. Also, another difference is that when using/mnt
, the mounted device will not automatically appear in the Naurilus’ left pane (the left pane that holds your directories like Desktop, Favorites, etc )/opt
- This directory is reserved for the installation of optional add-on applications or software packages. For Example, a lot of third-party programs are installed into the/opt
directory./proc
- In simple terms, this directory contains detailed information about all running processes in your system./proc
is a virtual file system, which means it doesn’t really contain any real life but rather, runtime system information. This directory (as you guessed) also contains ‘special files’ that represent the current state of the kernel and your system./root
- This directory defines the root directory of the system. To simplify it, think of the/root
as a house address that specifies where the root(/
) is./run
- This directory stores volatile runtime data since the system was started. The data stored in this directory is usually just needed during early boot to provide the system with the necessary tools for booting./srv
- This directory contains site-specific data that is served to the system. Example - data files for particular ‘services’ like FTP, WWW, or CVS. What is a service? A service is a process that runs all the time on your system/server./sys
- This directory also contains ‘special files’. These ‘virtual files’ contain all the information regarding the devices your system is connected to.❓Aren’t/sys
and/dev
technically the same? Both seem to store a list of devices that are attached to the system? What’s the need for having 2 different directories for the same thing.💡The/sys
contains files that basically provide information about the devices you are connected to, like, Is it powered on? Which devices are trying to access it? This information is useful for applications that actively use that device. The/dev
contains files that allow access to the device themselves. Like, How can I access the file to write data into it? How can I manipulate it?💡Think of the/sys
as the outer boundary, which can only give you information about what is inside. You cannot directly access it or change it in any way. On the other hand,/dev
is what is inside the boundary, it gives you a way to get inside the boundary to directly manipulate what's inside./tmp
- This directory is used to store temporary data that might be useful for a short period of time, by both user programs and system programs. The data in these files are generally removed when it is no longer needed.❓Both the/tmp
and/run
store temporary and volatile data that gets cleared with every boot. What is the difference?💡/tmp
can be considered as a dumping ground for all and every program, process, or user that is on your system. There is no ‘permission’ required to access this directory. Any program can redirect its temporary files to this folder. But this is not the case for/run
./run
is strictly reserved only for the system and the public cannot write to this file. This prevents mess up in data from unwanted access. It is reserved for services like sockers, locks, and other data that is non-persistent (cannot retain their original form after change) in nature.😀In a nutshell,/run
exists so people don't access important system data, stored in/tmp
and mess it up because they don't know what they are doing/usr
- This directory is a system-wide read-only access after the user has mounted. In a nutshell, every command you run when you are logged in from your Linux system is stored here. The/usr
directory has its own/bin
and/sbin
files that store the binaries generally used by the user./var
- This directory basically holds programs that are frequently changed. Like webpages, servers, etc.❓How is the/bin
different from the/usr/bin
?💡/bin
contains all necessary binaries required for running the system on a single-user mode ( no login in simple terms ). The binaries in/bin
are used for recovering your system or to repair it. These binaries can be accessed without needing a user login. But,/usr/bin
binaries can only be accessed after the/usr
has been mounted and the user has logged in. The binaries in/usr/bin
usually consist of commands that the user uses (both system and installed commands)
So that was a brief summary of all the file directories in Linux systems.
Author's Note
I hope this article was useful! If you would like me to explain any part of it in more detail, then please drop a comment in the comment section below.
If you found any faults in my content then you could just drop me a quick DM on my social media handles.
Thank you for reading :)