Linux Vs Windows File System
Linux file system is a hierarchical tree structure. We have the root folder just like a tree root and inside the root folder we have different folders which has it's own purpose and inside those folders, we have other folders and files.
In comparison the Windows file system does not have one root folder where all folders extend from, rather it has multiple root folders. We have disks or drives as root folders. Earlier in the era of insertable disks like floppy disks or CDs windows used letters to assign drives for each insertable disks. Eg: A and B were removable disks. When HDDs were added to PCs, the letter C became the letter for the internal disk or hard drive and after that all additional disks were given the next available letters and it has stayed the same until now. That's how the file system is different from that of Linux
Linux file system overview
The Graphical User Interface (GUI) always has this graphical file system view. The file-explorer program shows us the folders and files in a graphical representation that we can navigate easily.
When you click on the file explorer application on the left pane, it opens up the home directory by default. Every user on Linux gets their own space inside the home directory. There will be some default directories created along with the home directory like Documents, Downloads, Music, etc. The home directory is actually one of the folders in the root of the file system.
How can you see the root folder and other directories?
Well if you click on + Other Locations, we can get there
Now I am inside the root directory. Inside the root directory, we can see the home directory. This is basically where all Linux users' personal space is created. Each user has their own space in the home directory except for the root user which actually has its own isolated folders separated from all other users. The folder named /root
is the home directory of the root user and /home
directory is the home directory for all other users.
If you open the home directory you can see the user's home directory
In my case, the Linux user is osboxes and if you double-click osboxes it will take you back to the first screenshot.
It is important to isolate users and their personal space to keep their programs, configurations, editors, and so on private for each user. Meanwhile, there are some programs that are installed systemwide. This means these programs are available for all users on that computer. They are available outside the home directory. These can be applications or linux commands that are available for the system and all other users.
/bin
bin stands for binaries. /bin
folder inside the root directory contains the executables for most essential user commands. some examples of the files inside the /bin
folder include commands like cat, cp, calendar, echo, etc. Most of the basic Linux commands can be found here
What is a binary?
Binary is a computer-readable format that the computer understands. Instead of a text, it is a combination of 1s and 0s. The executables must be in binary for the computer to understand. This is why all these commands are in the bin folder.
/sbin
sbin are also binaries but system binaries. These commands are system-relevant. These commands need a super user permission to execute them. Examples of these commands are adduser, passed, chpasswd, iptables for network configuration, etc. All these commands need super user privilege which normal users don't have. These commands are mostly used by system administrators to administer the system and also by the system itself.
/lib
Lib stands for libraries. This directory contains essential shared libraries that executables from /bin
or /sbin
use. If the commands in bin or sbin need any libraries to access, they are fetched from this directory. So we can understand that one single program can be split into different locations like having executables in /bin
directory and libraries in /lib
directory which is a common way of splitting location of program when you install them in Linux
/usr
usr stands for user. Originally this was used as the user directory before home directory came into the picture. If we look inside the /usr
directory we see a bunch of folders. We have /bin
,/sbin
,/lib
folders just like we have in the root directory at user level. The same commands we see in the root folders binary folders can be seen inside the usr directory as well. It is because there is a historical reason. As the UNIX system design had storage limitations in the older days, it was split to root binary folders and user binary folders. The duplication doesn't make sense in modern era of storage solutions. However, the concept remains from the old times. Also whenever we execute common Linux commands they are executed from the user's bin folder.
/usr/local/
Inside /usr/local
folder we can again see bin, sbin and lib directories. Here the differentiation is pretty clear. This is where third party applications that YOU as linux user install on the computer goes. Applications like docker, minikube, java, etc will go here.
Note again that the /usr
folder is inside the root. So everything that is installed in the local folder will be available for all users on the computer. It is a systemwide installation. For eg: if you install docker in /usr/local
every user in the system can access docker. However, in linux it is possible to install applications specific to users' by installing it in the user's home directory
/opt
This is another location where some third-party programs that you install will be placed.
So what's the difference between /usr/local
and /opt
?
There are some apps that do not split their code or files into different directories like having binaries and libraries in different folders. They have all the binaries and libraries in the same folder. Examples of such applications are most of the IDEs (code editors). They will be usually installed under /opt
where everything is under one folder
These applications are also available systemwide for all users.
/boot
This directory contains the files for booting the system. You need to be careful handling this directory.
/etc
This is the directory where most of the system configuration files are stored. Configuration files like network configuration, linux user data, passwords. This directory stores the configuration for system-wide applications. These files are not read-only. They are writable also.
/dev
dev stands for devices. This is the location of device files like keyboard, mouse, hard disk, webcam, etc. Applications regarding the hardware connected to your computer will be placed in this directory
/var
When the operating system starts, it actually logs some data. And these logs are stored in a folder inside /var
called /var/log
. It also contains /var/cache
directory which contains cached data from applications. Basically /var
folder contains logs from different processes and applications that are running on your computer
/tmp
We also have a temporary folder where temporary resources required for some processes are kept here temporarily. At some point, they will be deleted usually at system reboots.
/media and /mnt
Media is basically where your external media is mounted. It contains subdirectories, where removable media devices inserted into the computer are mounted.
Example external hard drive, network drive, USB drives, etc. They will also be referenced in the /dev
folder.
For manually mounting for eg: file systems to your OS you have this /mnt
folder.
Usually we are not interacting with these folders directly. Most of the time these are automatically dealt by the package managers.
But when you are debugging or troubleshooting it is good to know where the files are located. I have used ubuntu 22.04 to demonstrate the file structure.
Top comments (4)
Nice article. A few comments.
The magic that makes the LFS work is the PATH in the environment that tells programs where to look for executables and in what order. That needs to be mentioned at least briefly. Things are stored in $HOME/bin because they are (supposed to be) executable. With the proper shebang/magic number almost anything can be executable. It doesn't have to be binary. They are put there because it is often one of the first entries in the PATH and can be used to override things with the same names in directories in subsequent PATH entries.
AFAIK, most files in /etc are write protected unless you have elevated permissions. Usually, they are copied into another directory that the user has write access to when they need to be customized or there is another user accessible file in an earlier PATH entry, etc. for the user to modify as necessary.
You left out a few. /proc and /sys are virtual directories that help you interact with your hardware and operating system without using complicated system calls directly.
/run is used for information that will not persist between boots. I haven't explored it much.
Thank you for your valuable feedback, it is insightful and a learning for me as well. I tried to document my learnings somewhere and ended up posting this article. Thank you for taking your time in reading the article and for your valuable suggestions. I am not a seasoned writer. The points you mentioned are very important. There is always room for improvement. Cheers!
well documented and explicit, thanks for sharing
Thank you for your feedback.