Linux Directory Structure Explained.

Vatsal
6 min readJul 5, 2022

--

If you’re coming from Windows, the Linux file system structure can seem particularly alien. The C:\ drive and drive letters are gone, replaced by a / and cryptic-sounding directories, most of which have three-letter names.

The Filesystem Hierarchy Standard (FHS) defines the structure of file systems on Linux and other UNIX-like operating systems. However, Linux file systems also contain some directories that aren’t yet defined by the standard.

Types of files in the Linux system.

  1. General Files — It is also called ordinary files. It may be an image, video, program, or simple text file. These types of files can be in ASCII or Binary format. It is the most commonly used file in the Linux system.
  2. Directory Files — These type of files are a warehouse for other file types. It may be a directory file within a directory (subdirectory).
  3. Device Files — In a Windows-like operating system, devices like CD-ROM, and hard drives are represented as drive letters like F: G: H whereas in the Linux system device are represented as files. As for example, /dev/sda1, /dev/sda2 and so on.

These are the common top-level directories associated with the root directory:

  • /bin — binary or executable programs.
  • /etc — system configuration files.
  • /home — home directory. It is the default current directory.
  • /opt — optional or third-party software.
  • /tmp — temporary space, typically cleared on reboot.
  • /usr — User related programs.
  • /var — log files.

Some other directories in the Linux system:

  • /boot- It contains all the boot-related information files and folders such as conf, grub, etc.
  • /dev — It is the location of the device files such as dev/sda1, dev/sda2, etc.
  • /lib — It contains kernel modules and a shared library.
  • /lost+found — It is used to find recovered bits of corrupted files.
  • /media — It contains subdirectories where removal media devices inserted.
  • /mnt — It contains temporary mount directories for mounting the file system.
  • /proc — It is a virtual and pseudo-file system to contains info about the running processes with a specific process ID or PID.
  • /run — It stores volatile runtime data.
  • /sbin — binary executable programs for an administrator.
  • /srv — It contains server-specific and server-related files.
  • /sys — It is a virtual filesystem for modern Linux distributions to store and allows modification of the devices connected to the system.

The base of the Linux/Unix file system hierarchy begins at the root and everything starts with the root directory.

/ — The Root Directory

Everything on your Linux system is located under the / directory, known as the root directory. You can think of the / directory as being similar to the C:\ directory on Windows — but this isn’t strictly true, as Linux doesn’t have drive letters. While another partition would be located at D:\ on Windows, this other partition would appear in another folder under/on Linux.

/bin — Essential User Binaries

The /bin directory contains the essential user binaries (programs) that must be present when the system is mounted in single-user mode. Applications such as Firefox are stored in /usr/bin, while important system programs and utilities such as the bash shell are located in /bin. The /usr directory may be stored on another partition — placing these files in the /bin directory ensures the system will have these important utilities even if no other file systems are mounted. The /sbin directory is similar — it contains essential system administration binaries.

/boot — Static Boot Files

The /boot directory contains the files needed to boot the system — for example, the GRUB boot loader’s files and your Linux kernels are stored here. The boot loader’s configuration files aren’t located here, though — they’re in /etc with the other configuration files.

/cdrom — Historical Mount Point for CD-ROMs

The /cdrom directory isn’t part of the FHS standard, but you’ll still find it on Ubuntu and other operating systems. It’s a temporary location for CD-ROMs inserted in the system. However, the standard location for temporary media is inside the /media directory.

/dev — Device Files

Linux exposes devices as files, and the /dev directory contains a number of special files that represent devices. These are not actual files as we know them, but they appear as files — for example, /dev/sda represents the first SATA drive in the system. If you wanted to partition it, you could start a partition editor and tell it to edit /dev/sda.

This directory also contains pseudo-devices, which are virtual devices that don’t actually correspond to hardware. For example, /dev/random produces random numbers. /dev/null is a special device that produces no output and automatically discards all input — when you pipe the output of a command to /dev/null, you discard it.

/etc — Configuration Files

The /etc directory contains configuration files, which can generally be edited by hand in a text editor. Note that the /etc/ directory contains system-wide configuration files — user-specific configuration files are located in each user’s home directory.

/home — Home Folders

The /home directory contains a home folder for each user. For example, if your user name is bob, you have a home folder located at /home/bob. This home folder contains the user’s data files and user-specific configuration files. Each user only has write access to their own home folder and must obtain elevated permissions (become the root user) to modify other files on the system.

/lib — Essential Shared Libraries

The /lib directory contains libraries needed by the essential binaries in the /bin and /sbin folder. Libraries needed by the binaries in the /usr/bin folder are located in /usr/lib.

/lost+found — Recovered Files

Each Linux file system has a lost+found directory. If the file system crashes, a file system check will be performed at next boot. Any corrupted files found will be placed in the lost+found directory, so you can attempt to recover as much data as possible.

/media — Removable Media

The /media directory contains subdirectories where removable media devices inserted into the computer are mounted. For example, when you insert a CD into your Linux system, a directory will automatically be created inside the /media directory. You can access the contents of the CD inside this directory.

/mnt — Temporary Mount Points

Historically speaking, the /mnt directory is where system administrators mounted temporary file systems while using them. For example, if you’re mounting a Windows partition to perform some file recovery operations, you might mount it at /mnt/windows. However, you can mount other file systems anywhere on the system.

/proc — Kernel & Process Files

The /proc directory is similar to the /dev directory because it doesn’t contain standard files. It contains special files that represent system and process information.

/sbin — System Administration Binaries

The /sbin directory is similar to the /bin directory. It contains essential binaries that are generally intended to be run by the root user for system administration.

tmp

/tmp — Temporary Files

Applications store temporary files in the /tmp directory. These files are generally deleted whenever your system is restarted and may be deleted at any time by utilities such as tmpwatch.

/var — Variable Data Files

The /var directory is the writable counterpart to the /usr directory, which must be read-only in normal operation. Log files and everything else that would normally be written to /usr during normal operation are written to the /var directory. For example, you’ll find log files in /var/log.

If you found this helpful, make sure to show your support with a clap, and if you want to help others in their projects, a share would be greatly appreciated! Let me know what you think about this! Happy Learning!

--

--

Vatsal
Vatsal

Written by Vatsal

Hi 👋, I’m Vatsal. A passionate Software Developer | Fun fact: Funny, Anime-addict, EDM, Binge Watcher. | Follow Me on GitHub: https://github.com/codeArtisanry

No responses yet