Overview of Linux Directory Structure With Examples

Linux filesystem provides various high-level directory structures and all these directories used for a specific purpose. In the Linux filesystem hierarchy, the topmost directory is the Root partition and it is denoted by the   " / ". 

We will go through each Linux directory structure and understand their use cases.

To know about the Linux directory structure, you can install a tool called tree on your Linux pc.

# On Ubuntu:  
$ sudo apt-get install tree

# After finished installation,this command shows all folders and their subfolders and prints all files present in the systems.
$ tree /

# This command shows one level of subfolder and their files.
$ tree -L 1 /

Root directory structure

" / ": (Root):

All the directory structures start from this Root directory. this directory contains /boot , /etc , /usr/ /bin, /sbin etc.

Now we will see each directory under the Root directory.

/boot:

This directory contains files that are required during the system boot.

# This command Shows the /boot directory structure 
$ tree -L 1 /boot

boot directory structure

config-*: This config file provides information about which kernel module is enabled or not.

# Kernel configuration file
$ cat config-4.15.0-120-generic

# CONFIG_EXT2_FS is not set
# CONFIG_EXT3_FS is not set
CONFIG_EXT4_FS=y
CONFIG_EXT4_USE_FOR_EXT2=y
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_EXT4_FS_SECURITY=y

During the kernel compilation, You can enable or disable these kernel configuration, and late you can check your kernel configuration using this file.

initrd.img-*: It stands for initial ramdisk. Kernel load initrd.img into the RAM during the boot time and initrd provides the temporary file system during booting time before mount the actual root file system mount.

vmlinuz-*: It is a compressed Linux kernel. normally vmlinuz is used on x86 based system so GRUB (x86 based bootloader) uncompressing the vmlinuz and load into the memory.

System.map-*: It is the symbol table of the Linux kernel. it provides the lookup table between a symbol name and their address. the symbol name can be the name of a variable or name of a function. this file is very useful for debugging the kernel panic and kernel oops.

grub/grub.conf: This file contains GRUB bootloader related configurations.

/bin:

  • It contains the executable files that all users can access.
  • /bin directory contains binary of basic commands like ls, cp, date, cat, echo, etc.

/sbin:

  • It contains the system related binary which needs superuser permission.
  • /sbin contains binary commands that are used to change the system property, disk management, etc.
  • Example- fsck, ifconfig

/usr/bin:

  • After system bootup, when you installed the package locally those binaries present in this directory.
  • Example: find, nmp,rar, diff

/usr/sbin:

  • This directory contains the system utilities that are used after the system bootup.
  • Mostly it contains the binaries for the system administrator.
  • Example: bluetoothd, rmt

/dev:

  • It is refers to the device.
  • In Linux, it considers all the hardware device is a file and these files are present inside the /dev directory.
  • These files are created dynamically .so when you insert any USB device then their entry is dynamically created in /dev.
  • There is two most important file.
  • /dev/null: To discard output/error use this file and their size is always zero
  • /dev/zero: To create a particular size of the file that contains null or zero.
# To discard the output.
$ cat file > /dev/null 

# Create the 1 KB size of the file that contains zero or null
$ dd if=/dev/zero of=/tmp/zero.txt bs=1024 count=1

/etc:

  • This folder contains the system configuration files.
  • It also contains the system start/stop script.
# It gives the hostname of your machine
$ cat /etc/hostname

# It provides the list of modules to be loaded at boot time
$ cat /etc/modules

/lib:

  • This directory contains all the library files that used during execution of binary present at in the system.
  • It contains all the static and dynamic library files.
  • Example: libsepol.so.1, libx86.so.1

/home:

  • This directory is for all users to store personal data.
  • Example: /home/tutorial

Add comment


Security code
Refresh