Linux File Structure Explained

Once upon a time there was a thing called MS-DOS.

DOS = DISK OPERATING SYSTEM, command line only operating system. Eventually Microsoft came up with Windows on top of DOS and Later Windows boots without DOS.

All the windows boots files are stored on the file called you know.. “Windows”.

Why I said that is this is more usual to us as we all have worked with windows since the school days.

But, The LINUX is different and it does not install application like the windows does. ( remember →Program files folder in Windows )

So, This article will explain what is the Linux File Structure.

Intro

All started when Linus Torvalds invented Linux itself. In 1991.

Torvalds was a student at the University of Helsinki in Finland where he had been using Minix, a non-free Unix-like system, and began writing his own kernel. He started by developing device drivers and hard-drive access, and by September had a basic design that he called Version 0.01. This kernel, which is called Linux, was afterwards combined with the GNU system to produce a complete free operating system. --https://www.livinginternet.com/i/iw_unix_gnulinux.htm--

Things different from Windows

Forward Slash

Linux follows Unix traditions. That’s why Linux uses forward slash ( / ) instead of backslash ( \ ) like in Windows OS.

Case Sensitivity

Another interesting thing in Linux is that the files system is Case Sensitive. So we can create folders like follows. ( cannot be done in Windows )

Linux allows this because technically all these files have different names.

Linux File Structure

If you have worked with Mac you’ll find a similarity with Linux. That is because both of them evolves from UNIX system.

This is the route for the system of Linux. This layout is outlined in the filesystem hierarchy standard or FHS which defines the structure and this is maintained by the Linux Foundation.

Ok !! Let’s start exploring the root folder from the beginning.

1. bin

Bin is the short term for binaries. This folder stores the basic binaries or the programs / applications.

ex: ls, cat, df, dir, dd, bash etc…

There is another folder called sbin.

sbin — system binaries

sbin will store the functions for the admin only. Other users will not have the permission to use these functions.

Both of these folders can accessed in single user mode.

Single User Mode is a special mode that boots you in as a root user to allow you to do system repairs, upgrading or testing.

Remember !!! when you install the program it will not be placed in these folders.

2. boot

This is folder which is very dangerous to mess with unless you want to break the system. ha ha :D

This folder includes everything the OS needs to boot in.

Boot loaders lives here

3. cdrom

This is the mounting point for your computer CD ROM.

4. dev

This is where you can see all your devices list. This place is a good place which show Linux follows Unix tradition — “Everything is a File”. So All your computer devices can be seen here as a file.

ex:

Your hardware disks as sda, and the partition for that is as sda1, sda2, sda3

This area will be accessed by the applications and the drivers.

5. etc

etc is for excreta (edit to configure). This folder will contain all your system wide configurations.

ex: apt, cron job configurations , etc.

6. home

Where we can store the personal files for each user. Inside this there will folders for each user.

Each user have their own home folder and that specific user can only access that unless user has the admin permissions.

Home folder contains many different directories which store your applications settings. ex: the name starts with ‘.’ (period).

These files are hidden by default.

Default Home folder will be

To see the hidden files we can tick on show hidden files check box in the file manager.

After you will see all the files inside.

.cache → will store your browser data and thumbnails and etc.

All system desktop setting will be save here in hidden files. What theme you use and icon sets, settings for your IDEs, Terminal settings etc.

These hidden files are important if you wanna backup your settings.

7. lib

Where the libraries are stores. These are required by the binaries in bin and sbin.

8. media

Where the external devices get mounted. Your Pen drive, and other devices.

mnt is for manually mounted devices.

media is used directly by the OS to mount the devices.

9. opt

This is the Optional folder. Which is used for manually installed software from vendors resides.

ex: I have installed Zoom and Google Chrome. These files can be seen inside opt.

10. proc

This file includes pseudo files that contain information about system processes and the resources.

Every process will have directory here contains all information on that process.

As an example here is the result I get from the top command

PID shows the process IDs. These process ids are there in the proc folder.

11. root

This is the root users home folder. You can store files here and you need the root permission to access it.

12. run

This folder include the things in the RAM. Which mean these files inside will go off when you reboot the machine or shutdown. This folders stores the runtime information for the processes.

13. snap

This is where the snap packages are stored. Mainly used by Ubuntu.

14. srv

srv = service

This directory stores the service data. This folder will will contain data if you run a server like ftp or Web server. So external users can access here files with a better security.

15. sys

sys = System folder

This is to interact with the kernal. This is actually stored in the HDD but this is logical and created everytime after the booting process. So you can’t store anything here.

16. tmp

tmp = temporary directory

This folder will store the temporary files which is used by the sessions.

ex: Word processor temp files.

If something crashes, that specific application can look into this file to look for the copy.

This folder is empty when reboot.

Sometimes there are some files remains because the system can’t delete them. If this is irritating you log in as single mode user and manually delete the files.

17. usr

usr = User Application Folder

This is where we can find the installed application for the user. Inside the folder you’ll see the bin, sbin, lib. These are there for the system admin to do their maintenance.

This folder is also know as UNIX system resource.

All applications installed here are considered as non-essential for basic system operations.

Programs which is installed through source code will end up in the folder “local

Large programs are installed in the folder “share

Any source codes and kernel files will go to the folder “src

18. var

var = Variable directory

This contains the files or the folders which are expected to grow in size.

ex: log files, crash reports, etc.

Also you can see the temporary printer queues, temporary files for databases for mail.

Also know as the spool.

As you can see Linux is very different from Windows.

You might think this is a mess but it’s actually a more efficient way of doing things and allows more sharing of common resources.

Here is a good video about the file structure if you wanna check more details.

Okay, That;s it then.

May the force be with you !!!

Senior Software Engineer ❤️ Node | Ruby