Linux file system structure

Linux Operating System and Linux File System are totally different from Microsoft Windows. In Microsoft Windows, you usually see Windows is installed in C:\ drive. In Linux, the Filesystem Hierarchy Standard (FHS) defines the structure of file systems on Linux and other UNIX-like operating systems, everything is configured as a file including directories, partitions, and hardware device drivers. All files and directories will be displayed under the root directory, even if your data is stored on different physical devices. I have explained what is Linux, now let’s dig a little deeper into Linux file system structure.

Linux file system layout

This is a layout file system structure from a CentOS linux, depends on the system and linux distro, the structure may vary, and directories may be removed or added.

/ – The Root Directory

Everything on Linux system is located under the / or root directory. The meaning of / or root and root user are often confusing to new Linux users. In Linux, the root directory “/” (The tree of the file system starts at the trunk or slash, indicated by a forward slash /) is a separator between a file and a directory contains all underlying directories and files, yet root user is a super user or administrator user with has administrative privileges on the system vs Linux privileged users who only have limited privileges to protect system security.

/bin – Essential command binaries

The /bin directory is a place contains most commonly essential executable terminal binaries programs or file required during booting, repairing like cat, ls, mount, rm, du, df, tar, rpm, wc, etc.

/boot – Boot loader files

All of the required files to boot the system contains in /boot directory, including GRUB boot loader’s files, Linux kernels, the Linux initial RAM disk (initrd),

/dev – Device Files

All of the hardware devices on the machine like cdrom, cpu, hard drives, etc will be stored as special device files that represent all the devices in /dev directory. Device files are created during your Linux system installation.

/etc – Configuration Files

Contain host-specific files and directories, e.g. information about system and application configuration files like startup, shutdown, start, stop script for every individual program. In another word /etc data is very similar to Control panel in Microsoft Windows.

/home – Home Directory

Home directory of the users. Every time you create a new user, a new directory with user’s name is created in /home directory for users to store their own files within their own home’s directory. Most common automatic directories created within /home ‘s user are Desktop, Downloads, Documents, Music, Movie, etc. Most programs configuration file for a specific user will be saved in it’s users /home directory like web browser settings, web browser bookmarks, desktop wallpaper, themes, and passwords.

/lib – Essential Libraries

Similar to Windows ‘dll’ files, all Linux shared libraries and kernel modules files stores in /lib directory. These important Linux dynamic libraries are required to boot the system and run commands in the root file system.

/lost+found – Recovering Files

Sounds weird but yes we have lost+found in Linux file system structure. Every Linux file system and partitions has a lost+found in it’s directory. In the even your system is crashed or unexpected shutdown, you can run fsck command to check and repair the filesystem, fsck will turn any corrupted or almost-deleted files back into files that you can recover them later in /lost+found directory.

/media – Removable Media Devices

Every time you insert a removable device such as external hard drive, floppy disk, zip drive, CDs, DVDs, flash drive to a Linux system, a new directory will automatically be created inside the /media directory. /media directory is a temporary mount directory for removable devices.

/mnt – Temporarily mounted filesystems

While /media is where the system automatically mounts removable media, /mnt is for you to mount things (partitions, file systems, devices) manually and temporarily.

/opt – Optional software packages

The /opt directory is reserved to store addition software or extra and third-party software for your system, those addition software usually don’t follow the standard file system hierarchy and not handled by the package manager.

/proc – Kernel & Process Information

Similar to /dev, /proc directory contains information about running process, system resources and information. You can view information about any running process with a specific process-id (pid) or hardware’s information such as memory, cpu, io, etc…

/root – Root Home Directory

Don’t be confused with “/” or root directory, /root is a root account’s home directory determined by developer or local preference rather than /home/root to allow for booting the system even if /home/ is not available.

/sbin – System binaries

Similar to /bin, /sbin contains essential binaries that are generally intended to be run by the root user for system administration and maintenance purpose. For example: iptables, reboot, fdisk, ifconfig, swapon, init, ip, mount

/selinux – Security-Enhanced Linux

Selinux comes with RedHat based distro (fedora, centos), selinux is a security architecture integrated into the 2.6.x kernel using the Linux Security Modules (LSM). For some reason Centos 6 created an emtpry selinux directory in root directory, the real selinux directory with its configuration files are stored in /etc/selinux/ directory.

/srv – Service Data

Server (srv) contains data of services such as HTTP, FTP, rsync, cvs

/sys – virtual filesystem

Some newer Linux distros have /sys directory with sysfs virtual filesystem to store information and statistics about (physical and virtual) device and device names. /sys is newly added since Linux kernel 2.6 /sys contains similar information with /proc which display device information about the kernel’s view of the system.

/tmp – Temporary files

System’s Temporary Directory, all users and programs in your system can access/read/write in this directory. You should not save/store any important files/directories under /tmp since all files will be removed after system is rebooted.

/usr – binaries, documentation, source code, libraries

Pronounced as ‘user’, /usr contains the majority of user utilities, programs, libraries, documentation etc for all user-related second level programs rather than applications and files used by the system.

/var – Variable Files

Variable or /var contains data that is expected to change and grow as the system is running (log, mail, spool, temp)

Leave a Comment

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