File System Hierarchy of Linux

By | February 17, 2018

The File System Hierarchy of Linux is basically the directory structure of Linux which gets created when we install Linux operating system. We all know everything in the Linux System or we can call Unix System are files. Every Command We use in Linux is a “C” Program which performs certain operations. Every flavour of Linux follows Filesystem Hierarchy Standard (FHS)  structure. When we install Linux, it comes up with multiple directories and everything which runs or exists on Linux machine whether it is a process or a configuration files resides under those directories.

Linux File System hierarchy or we can call Linux directory structures use a Single rooted and inverted tree-like directory structure, which I will show you with simple pictorial representation and brief but clear descriptions.

Above picture shows the simplified file system hierarchy of Linux, this you  can also  see on your Linux machine that all the directory created in the Linux system resides under “root directory (/)”

Sample Output

root@devopsage:~$ cd /
root@devopsage:/$ ls -l
total 112
drwxr-xr-x   2 root root  4096 Feb  6 11:10 bin
drwxr-xr-x   3 root root  4096 Feb  9 11:09 boot
drwxrwxr-x   2 root root  4096 Oct 26 16:55 cdrom
drwxr-xr-x  20 root root  4200 Feb 17 11:09 dev
drwxr-xr-x 146 root root 12288 Feb  9 11:09 etc
drwxr-xr-x   3 root root  4096 Oct 26 16:55 home
drwxr-xr-x  23 root root  4096 Dec 21 11:16 lib
drwxr-xr-x   2 root root  4096 Feb  6 11:07 lib64
drwx------   2 root root 16384 Oct 26 16:53 lost+found
drwxr-xr-x   3 root root  4096 Oct 26 12:03 media
drwxr-xr-x   2 root root  4096 Jul 20  2016 mnt
drwxr-xr-x   6 root root  4096 Feb  6 11:11 opt
dr-xr-xr-x 252 root root     0 Feb 17 11:09 proc
drwx------  25 root root  4096 Feb  6 16:48 root
drwxr-xr-x  31 root root   980 Feb 17 13:39 run
drwxr-xr-x   2 root root 12288 Feb  6 11:10 sbin
drwxr-xr-x   2 root root  4096 Jun 30  2016 snap
drwxr-xr-x   2 root root  4096 Jul 20  2016 srv
dr-xr-xr-x  13 root root     0 Feb 17 11:09 sys
drwxrwxrwt  18 root root 16384 Feb 17 14:22 tmp
drwxr-xr-x  11 root root  4096 Jul 20  2016 usr
drwxr-xr-x  15 root root  4096 Nov 27 16:04 var
root@devopsage:/$

Explanation of Linux Directory System

     – Root Directory

  • It is the top level directory in the Linux filesystem hierarchy, every other directory resides under the root directory. It is the parent directory for all the other directories.
  • The only root user has the permission to write under this directory.
  • It can be Considered same as C:\ of Windows

/root  – Home Directory of root

  • It is the home directory of the root user, we can also call it as superuser
  • It provides the working environment for root user
  • No other user apart from root user can write in this particular directory
  •  It can be considered as  C:\Documents and Settings\Administrators of Windows

/home   -Normal user’s home directory

  • It is home directory for the normal users (non-root user)
  • It provides a working directory for rest of the other users in the Linux system.
  • It can be considered same as C:\Documents and Settings\Username of Windows
  • Examples: /home/john, /home/user1 and likewise. 

/etc  – Configuration Files 

  • It contains the configuration files, all the configuration related to any service is managed under /etc directory
  • Examples: /etc/passwd –> User information is managed here ,  /etc/hosts –> Local DNS Entries etc.
  • It Can be considered same as C:\Windows\system32\drivers\

/boot  – Bootable Loader Files

  • It Contain all the bootable files in the Linux
  • Example: vmlinuz, Initrd (initial Ram disk) and GRUB (Grand unified bootloader)

/usr  –  User Program

  • By default, software is installed in this directory (Linux sharable resources)
  • Can be considered same as C:\program files of Windows
  • /usr/bin contains user binary files for their program, you will also find other binaries here if it is not visible in       /bin.  example: wc, zcat, sed and likewise.
  • Unlike /usr/bin, /usr/sbin contains all the system administrator commands. ex:   yum, mount etc.
  • Binaries for both /usr/bin and /usr/sbin resides under /usr/lib/   

/opt  – Optional Directory 

  • It is an optional directory for /usr, It contains third party software 
  • Other software can be installed inside /opt or subdirectory inside the /opt.

/bin  – Binary Files

  • It Contains commands used by all the users in the system
  • It contains the command which can also be executed even in the single user mode.
  • Example: arch, cd, cp, less etc..

/sbin  – Super User Binary Files

  • It contains command used by the only superuser (root)
  • Normal user does not have permission to use command which is under /sbin
  • Example: fdisk, mount, iptables etc..

/lib – System Library

  • It contains library files used by operating systems
  • It can be considered same as DLL (Dynamic Link Libraries) of Windows
  • Library files in Linux have usually shared object files.

/proc – Process Directory

  • It has all the process files 
  • It is often called as virtual directory
  • Content of /proc directory is not static, they keep on changing
  • It also contains a lot of important information used by operating system.
  • Example: /proc/meminfo -> information of RAM, /proc/cpuinfo -> CPU information etc.

/dev  – Device files

  • Contains device files like /dev/hda for hard disk, /dev/cdrom for cd ROM
  • Its similar to the device manager of Windows.

/media  –  Removable Devices

  • It Contains all the removable media devices like CD-ROM, Pendrive etc.

/var  – Variable Data

  • It has variables data like mails, logs etc.
  • The data whose size keeps on increasing resides under /var (variable directory).

/mnt  – Mount Directory 

  • It is default mount point for mounting any partition.
  • By default, this directory is empty.

/tmp  – Temporary Directory

  • Its a temporary directory used to hold temporary files 
  • Content related to many software are automatically deleted after reboot or at some time intervals

/run  – Files Executes at Runtime

  • This directory is designed to allow applications to store the data they require in order to operate
  • This includes process IDs, socket information, lock files and other data which is required at run-time.
  • This files can’t be stored in /tmp/ because programs such as tmpwatch could potentially delete it from there.

/srv  – Service Directory

  • srv stands for service 
  • It contains server specific and service related files.

/sys  – Virtual File System Directory

  • It contains Information about the drivers, devices, and other kernel features.
  • It stores and allows modification of the devices connected to the system

Leave a Reply

Your email address will not be published. Required fields are marked *