0% found this document useful (0 votes)
6 views

The Linux File System Structure Explained

Uploaded by

Daniel Williams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

The Linux File System Structure Explained

Uploaded by

Daniel Williams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

The Linux File System Structure Explained

When I was first coming from Windows and exploring Linux, I found the Linux filesystem structure to
be a bit confusing, simply because I didn’t know anything other than the Windows file system for my
entire life. But after persisting through the learning curve, the mystery was unraveled and I can now
comfortably switch between Linux and Windows whenever needed, and I actually feel like I
understand the Windows file system better now after learning the Linux file system.
For me, the biggest difference between the two file systems is to understand where the root of the file
system begins. In Windows, the root begins at the drive letter, usually C:\, which basically means it
begins at the hard drive. In Linux however, the root of the filesystem doesn’t correspond with a
physical device or location, it’s a logical location of simply “/”. See the graphics below for a visual
representation.

Linux File System Structure Tree


Windows File System Tree

Another thing to remember is that in Linux, everything is a file. Or, more accurately, everything is represented
as being a file, while in Windows it may be displayed as being a disk drive.

For example, in Windows the hard drive is typically represented as C:\ in the file explorer, and it will even
display a little icon of the hard drive and display how much space is being used. In Linux, on the other hand,
the hard drive as represented merely as /dev/sda, which is really just a folder/directory, which in Linux is really
just a file that points to other files.

“o let’s take so e othe o e p a ti al e a ples. The Li u e ui ale t of ou Do u e ts folde i Wi do s


would be /home/username/Documents, whe eas i Wi do s it’s t pi all C:\Users\UserName\Documents.
These are actually pretty similar, but you can see where the differences lie.

So using the above Linux file system chart, we need to explore what each folder in the Linux file system is for,
which will help us to better understand how Linux works in general. Note that not every folder listed here or
pictured above necessarily appears in every Linux distro, but most of them do.

 / - this is k o as oot , the logi al egi i g of the Li u file system structure. Every single file path
in Linux begins from root in one way or another. / contains the entirety of your operating system.

 /bin - P o ou ed i as opposed to i e , this is he e ost of ou i a files a e sto ed,


typically for the Linux terminal commands and core utilities, such as cd (change directory), pwd (print
working directory), mv (move), and so on.

 /boot - This is where all the needed files for Linux to boot are kept. Many people, including myself, like
to keep this folder in it’s own separate partition on the hard drive, especially when dual-booting is
involved. A key thing to note is that even when /boot is stored on different partition, it is
still logically located at /boot as far as Linux is concerned.
 /dev - This is where your physical devices are mounted, such as your hard drives, USB drives, optical
d i es, a d so o . We’ e al ead e plo ed that t pi all , ou s ste ha d d i e is ou ted u de
/dev/sda, whereas your USB thumb drive might be mounted under /dev/sde. You may also have
diffe e t pa titio s o ou disk, so ou’ll see /de /sda , /de /sda , a d so o . I Wi do s, he ou
go to M Co pute o Co pute a d ou a see all of the ph si al de i es a d d i es o e ted
to your computer, this is the equivalent of /dev in Linux file structure.

 /etc - P o ou ed et-see , although so e also p efe to spell it out, is he e o figu atio files a e
stored. Configurations stored in /etc will typically affect all users on the system; whereas users can also
store configuration files under their own /home folders, which will only affect that particular user.

 /home - This is he e ou’ll spe d the o e hel i g ajo it of ou ti e, as this is where all of your
personal files are kept. The Desktop, Documents, Downloads, Photos, and Videos folders are all stored
under the /home/username directory. You can also store files directly in your /home folder without
going to a sub-folder, if you wish so. Typically, when you open a command-line terminal in Linux, the
default location that the terminal points to is your /home/username folde , u less ou’ e a uall
changed the default location to something else.

 /lib - This is where libraries are kept. You’ll oti e that a ti es he i stalli g Li u soft a e
packages, additional libraries are also automatically downloaded, and they almost always start with
lib-something. These are basically the files needed for your programs on Linux to work. You can think
of this folde as so e hat e ui ale t to the P og a Files folde o Wi do s, although it’s ot
exactly the same. Unlike Windows, libraries can be shared between many different programs, which
results in Linux installations typically being much more lightweight than Windows, because typically in
Wi do s ea h p og a eeds it’s o li a i stalled, e e if it’s edu da t a d al ead e ists fo
another program. Surely a benefit of Linux file system structure.

 /media - Another place where external devices such as optical drives and USB drives can be mounted.
This varies between different Linux distros.

 /mnt - This is basically a placeholder folder used for mounting other folders or drives. Typically this is
used for Network locations, but you could really use it for anything you want. I used to use it as the
ou t poi t fo edia se e ’s ha d d i e / t/se e .

 /opt - Optio al soft a e fo ou s ste that is ot al ead a aged ou dist o’s pa kage
a age . I do ’t eall e e fi d self using this, your mileage may vary.

 /proc - The p o esses folde he e a lot of s ste i fo atio is ep ese ted as files e e e ,
everything is a file). It basically provides a way for the Linux kernel (the core of the operating system)
to send and receive information from various processes running in the Linux environment.

 /root - This is the equivalent to the /home folder specifically for the root user, also called the
supe use . You eall do ’t a t to tou h a thi g i he e unless you know what ou’ e doi g.

 /sbin - “i ila to / i , e ept that it’s dedi ated to e tai o a ds that a o l e u the oot
user, or the superuser.

 /tmp - This is where temporary files are stored, and they are usually deleted upon shutdown, which
saves you from having to manually delete them like is required in Windows.

 /usr - Contains files and utilities that are shared between users.
 /var - This is where variable data is kept, usually system logs but can also include other types of data as
well.

You can do some more research online and go deeper to learn more about specific applications and usage of
each of the above mentioned folders, but for the typical everyday home user, your /home folder is generally
the o l folde ou’ll e di e tl i te a ti g ith. O casionally you may have to venture into the other folders
if ou’ e t i g to do so e t ou leshooti g, ut t pi all ode Li u dist os auto ati all ai tai these
folde s a d the e ui e little to o use i te fe e e. The e eptio ould e if ou’ e using a distro like Arch
Li u o Ge too, i hi h ase, ou p o a l did ’t eed to ead this a ti le i the fi st pla e.

Conclusion
To reiterate my previous statement, keep in mind that the Linux file system is a logical system, rather than a
physical one. Different folders in the system may be on different partitions on the disk, or even on different
disks altogether, but logically everything is still in the same location. The best way to grasp this concept is to
simply use Linux as your daily driver, as the best way to learn is through immersion. Ubuntu or Linux Mint are
probably the best choices for this task. After using the Linux file system for a while, eventually everything will
li k ou’ll u de sta d hat’s goi g o .

################################### End #####################################


Linux Directory Structure (File System Structure) Explained with Examples
Have you wondered why certain programs are located under /bin, or /sbin, or /usr/bin, or /usr/sbin?
For example, less command is located under /usr/bin directory. Why not /bin, or /sbin, or /usr/sbin?
What is the different between all these directories?
In this article, let us review the Linux file system structures and understand the meaning of individual
high-level directories.
1. / – Root

 Every single file and directory starts from the root directory.
 Only root user has write privilege under this directory.
 Please ote that / oot is oot use ’s ho e di e to , hi h is ot sa e as /.

2. /bin – User Binaries

 Contains binary executables.


 Common linux commands you need to use in single-user modes are located under this directory.
 Commands used by all the users of the system are located here.
 For example: ps, ls, ping, grep, cp.

3. /sbin – System Binaries

 Just like /bin, /sbin also contains binary executables.


 But, the linux commands located under this directory are used typically by system aministrator, for
system maintenance purpose.
 For example: iptables, reboot, fdisk, ifconfig, swapon

4. /etc – Configuration Files

 Contains configuration files required by all programs.


 This also contains startup and shutdown shell scripts used to start/stop individual programs.
 For example: /etc/resolv.conf, /etc/logrotate.conf

5. /dev – Device Files

 Contains device files.


 These include terminal devices, usb, or any device attached to the system.
 For example: /dev/tty1, /dev/usbmon0

6. /proc – Process Information

 Contains information about system process.


 This is a pseudo filesystem contains information about running process. For example: /proc/{pid}
directory contains information about the process with that particular pid.
 This is a virtual filesystem with text information about system resources. For example: /proc/uptime

7. /var – Variable Files

 var stands for variable files.


 Content of the files that are expected to grow can be found under this directory.
 This includes — system log files (/var/log); packages and database files (/var/lib); emails (/var/mail);
print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp);

8. /tmp – Temporary Files

 Directory that contains temporary files created by system and users.


 Files under this directory are deleted when system is rebooted.
9. /usr – User Programs

 Contains binaries, libraries, documentation, and source-code for second level programs.
 /us / i o tai s i a files fo use p og a s. If ou a ’t fi d a use i a u de / i , look u de
/usr/bin. For example: at, awk, cc, less, scp
 /usr/sbin contains binary files for system administrators. If ou a ’t fi d a s ste i a u de /s i ,
look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel
 /usr/lib contains libraries for /usr/bin and /usr/sbin
 /usr/local contains users programs that you install from source. For example, when you install apache
from source, it goes under /usr/local/apache2

10. /home – Home Directories

 Home directories for all users to store their personal files.


 For example: /home/john, /home/nikita

11. /boot – Boot Loader Files

 Contains boot loader related files.


 Kernel initrd, vmlinux, grub files are located under /boot
 For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic

12. /lib – System Libraries

 Contains library files that supports the binaries located under /bin and /sbin
 Library filenames are either ld* or lib*.so.*
 For example: ld-2.11.1.so, libncurses.so.5.7

13. /opt – Optional add-on Applications

 opt stands for optional.


 Contains add-on applications from individual vendors.
 add-on applications should be installed under either /opt/ or /opt/ sub-directory.

14. /mnt – Mount Directory

 Temporary mount directory where sysadmins can mount filesystems.

15. /media – Removable Media Devices

 Temporary mount directory for removable devices.


 For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD
writer

16. /srv – Service Data

 srv stands for service.


 Contains server specific services related data.
 For example, /srv/cvs contains CVS related data.

You might also like