Understanding the Filesystem (Directory Layout) In Linux


Every computer stores various types of data on a storage device such as hard disk, USB drive, etc. This data need to be positioned in a systematic way so that whenever needed operating system can fetch it easily.

A huge storage disk is divided into smaller chunks of sectors of size 512 bytes. Any data is represented as a file and occupies few sectors in the disk. The filesystem basically keeps the metadata of this file such as file type, owner, permissions, its location, etc. and used when needed to access.

The word filesystem is used in different ways at different places-

  • It is used for the entire directory tree in Linux which starts from / (root) directory
  • A filesystem is also referred to as a specific type of data storage format such as ext3, ext4, NTFS, fat32, etc. Linux supports various types of filesystems.
  • A directory or a logical volume mounted to a mount point in a Linux filesystem is also referred to as a filesystem

In this article, we are going to discuss the tree structure of directories in Linux.

Linux Filesystem

In Linux, everything is considered as a file including devices such as DVD-ROMs, USB drives, etc. And the filesystem is all in one directory tree. When a device is mounted, its filesystem is added to the directory tree. So it appears as an integral part of the cohesive filesystem. Many filesystems are auto mounted at the time of system boot. Manually you can disable it to not mount at the runtime. Now open your terminal and run the following command to display the list of directories inside the root –

ls /

Or install the tree program in debian based system with the following command –

sudo apt install tree -y

And then run the following command to display the hierarchical structure of directories –

cd /
tree | more

after executing this command use the space button to scroll up.

Linux Filesystem Directories

The Filesystem Hierarchy Standard (FHS) defines the directory structure and directory content in Linux distributions. If you navigate to the root directory you will see the following directories inside it.

/bin – Stands for binaries, it contains tools like ls, cp, etc

/boot – It contains the bootloader and other boot files.

/dev – It stands for device, all physical devices such as USB drive, etc are mounted here.

/etc – Stands for et Cetra, It contains configuration files and databases.

/home – It contains the user’s home directory and files.

/lib – Libraries of installed packages located in this directory.

/media – It is the default mount point for removable devices such as media players, USB sticks, etc.

/mnt – Stands for mount, this is a temporary mount point for regular filesystem or empty directories.

/opt – Contains locally installed software, optional software such as vendor-supplied application program should be located here.

/proc – Everything in Linux is considered a file. proc filesystem(procfs) is a virtual filesystem that displays the information of the process as a file.

/root – This is the home directory of the root user.

/sbin – It stands for system binaries, like /bin it also stores binaries but these binaries are only for root user

/srv – It contains server data, This holds site-specific data that is to be served by the system for protocols such as ftp, rsync, www, etc.

/sys – In some Linux distributions this directory contains sysfs a virtual filesystem that stores the information related to os and hardware.

/tmp – A place to store temporary files, system clear these files upon startup.

/usr – All the binaries, documentation, libraries, and header files for all the user applications are stored here.

/var – Stands for variable, the value of these changes whenever the system runs it includes log files, backup, mail, cache, etc.

Conclusion

In this article, you have seen the overview of top-level directories in Linux. It can vary slightly if you move distributions to distribution, overall it will be the same.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.