Linux Directory Structure
The Directory Structure in Unix & Linux are a unified Directory Structure where in all the directories are unified under the “/” Root file system. Irrespective of where the File System is physically mounted all the directories are arranged hierarchically under the Root file system.
The Linux Directory Structure follows the “Filesystem Hierarchy Structure (FHS)” maintained by the Free Standards Group although most of the distributions sometimes tend to deviate from the standards.
In this article, let us review the Linux filesystem structures and understand the meaning of individual high-level directories.
/bin : User Binaries
This directory contains all the executable binary programs (file) required during booting, repairing, files required to run into single-user-mode, and other important, basic commands like cat, du, df, tar, rpm, wc, history, etc. Commands used by all the users of the system are located here.
/boot : Boot Loader Files
This directory contains all files during boot-up process, including Linux Kernel. /boot contains the core components that actually allow the system to boot. Kernel initrd, vmlinux, grub files are located under /boot.
/dev : Device Files
Contains device files for all the hardware devices on the machine. Every hard drive, terminal device, input or output device available to the system is represented by a file here. Depending on the device, you can operate on the devices in different ways.
These include terminal devices, usb, or any device attached to the system. For example: /dev/tty1, /dev/usbmon0
/etc : Configuration Files
This directory is basically a configuration directory for various system-wide services. By default, this directory contains many files and subdirectories. It contains configuration files, startup, shutdown, start, stop script for all program. For example: /etc/resolv.conf, /etc/logrotate.conf
/home : Home Directories
The /home directory contains a home folder for each user. Every time a new user is created, a directory in the name of user is created within home directory which contains other directories like Desktop, Downloads, Documents, etc. 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. For example: /home/dennis, /home/steve
/lib : System 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
Temporary mount directory is created for removable devices viz., media/cdrom. This directory is typically empty at boot. Its real purpose is simply to provide a location to mount removable media. For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer
/mnt : Temporary Mount Points
Temporary mount directory where sysadmins can mount filesystems like external hard drives, etc. However, you can mount other file systems anywhere on the system.
/opt : Optional Packages
opt stands for optional. Its contains third party application software like Java, Nagios etc. Typically, it is used to store optional packages. In the Linux distribution world, this usually means packages and applications that were not installed from the repositories.
/proc : Kernel & Process Files
Its contains information about system process. This is a pseudo filesystem contains information about running process. For example: /proc/{pid} directory contains information about the process with that particular pid.
This means that we can check and modify different information from the kernel itself in real time. For instance, you can get detailed information about the memory usage by typing cat /proc/meminfo.
/root : Root Home Directory
This is the home directory of the administrative user (called “root”). It functions exactly like the normal home directories, but is housed here instead. Only root user has write privilege under this directory.
/run : Application State Files
This directory is for the operating system to write temporary runtime information during the boot process. In general, you should not have to worry about much of the information in this directory.
/sbin : System Administration Binaries
Just like /bin, /sbin also contains binary executables. Its contains binary executable programs, required by System Administrator, for Maintenance. Viz., iptables, fdisk, ifconfig, swapon, reboot, etc.
/selinux : SELinux Virtual File System
This directory contains information involving security enhanced Linux, the /selinux directory contains special files used by SELinux. Ubuntu doesn’t use SELinux, so the presence of this folder on Ubuntu appears to be a bug.
/srv : Service Data
This directory contains server specific and service related files. In most cases, this directory is not used too much because its functionality can be implemented elsewhere in the filesystem.
/tmp : Temporary Files
System’s Temporary Directory, Accessible by users and root. Stores temporary files for user and system, till next boot. It is writable by anyone on the computer.
/usr : User Binaries & Read-Only Data
It contains binaries, libraries, documentation, and source-code for second level programs. /usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp. /usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel. /usr/lib contains libraries for /usr/bin and /usr/sbin
/var : Variable Data Files
It contains files that change for mail log file, printers log files, temp 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.
/sys : Systemwide Device Directory
Modern Linux distributions include a /sys directory as a virtual filesystem, which stores and allows modification of the devices connected to the system.
Enjoy it!