Linux Directory Structure (File System Hierarchy) Explained with Examples
Are you new to Linux ? If so, I would advise you to understand the Linux Directory Structure (File System Hierarchy) first. Don’t panic/scare after seeing the below image (File System Hierarchy). Getting confusion about
/usr/sbin don’t worry, we are here to teach you like a baby.
The Filesystem Hierarchy Standard (FHS) defines the structure of file systems in Unix/Linux, like operating systems.
In Linux everything is a file, we can modify anything whenever it’s necessary but make sure, you should know what you are doing. If you don’t know, what you are doing & did something without knowing anything which will damage your system potentially. So try to learn from basic to avoid such kind of issues on production environment.
/ : The Root Directory – Primary hierarchy root and root directory of the entire file system hierarchy which contains all other directories and files. Make a note
/root is different.
/bin : Essential User Binaries – Contains Essential User Binaries, where all the users performing most commonly used basic commands like ps, ls, ping, grep, cp & cat
/boot : Static Boot Files – Contains boot loader related files which is needed to start up the system, such as Kernel initrd (Initial RAM Disk image), vmlinuz (Virtual Memory LINUx gZip – compressed Linux kernel Executable) & grub (Grand Unified Bootloader). Make a note, its a
vmlinuz not a
vmlinux vmlinuz – Virtual Memory LINUX, Non-compressed Linux Kernel Executable
/dev : Device Files – contains all device files for various hardware devices on the system, including hard drives, RAM, CPU, tty, cdrom, etc,. It’s not a regular files.
/etc : Configuration Files – contains system global configuration files, which affect the system’s behavior for all users when you modifying anything on it. Also having application service script, like (start, stop, enable, shutdown & status).
/home : User’s Home Directories – Users’ home directories, where users can save their persona files.
/lib : Essential Shared Libraries – Contains important dynamic libraries and kernel modules that supports the binaries found under /bin & /sbin directories.
/lost+found : Recovered Files – If the file system crashes (It happens for many reasons, power failure, applications are not properly closed, etc,.) the corrupted files will be placed under this directory. File system check will be performed on next boot.
/media : Removable Media – Temporary mount directory for external removable media/devices (floppies, CDs, DVDs).
/mnt : Temporary Mount Points – Temporary mount directory, where we can mount filesystems temporarily.
/opt : Optional Packages – opt stands for optional, Third party applications can be installed under /opt directory, which is not available in official repository or proprietary software.
/proc : Kernel & Process Files – A virtual filesystem that contains information about running process (/proc/(pid), kernel & system resources (/proc/uptime & /proc/vmstat).
/root : Root Home Directory – is the superuser’s home directory, which is not same as /.
/run : Application State Files – is a tmpfs (temporary file system) available early in the boot process, later files get truncated at the beginning of the boot process.
/sbin : System Administration Binaries –
/sbin also contains binary executable similar to /bin but it’s require superuser privilege to perform the commands, which is used for system maintenance purpose.
/selinux : SELinux Virtual File System – Security-Enhanced Linux (SELinux) is a Linux kernel security module that provides a mechanism for supporting access control security policies, applicable for RPM based systems, such as (RHEL, CentOS, Fedora, Oracle Linux, Scentific Linux & openSUSE).
/srv : Service Data – srv stands for service, contain data directories of varies services provided by the system such as HTTP (/srv/www/) or FTP(/srv/ftp/)
/sys : virtual filesystem or pseudo file system (sysfs) – Modern Linux distributions included a /sys directory, since 2.6.X kernels. It provides a set of virtual files by exporting information about various kernel subsystems, hardware devices and associated device drivers from the kernel’s device model to user space.
/tmp : Temporary Directory –
/tmp stands for Temporary (Temporary Files) – Applications store temporary files in the /tmp directory, when its running/required. Which will automatically deleted on next reboot.
/usr : User Binaries – Contains binaries, libraries, documentation and source-code for second level programs (read-only user data). Command binaries (/usr/bin), system binaries (/usr/sbin), libraries (/usr/lib) for the binaries. source code (/usr/src), documents (/usr/share/doc).
/var : Variable – var stands for Variable, It contains Application cache files (/var/cache), package manager & database files (/var/lib), lock file (/var/lock), various logs (/var/log), users mailboxes (/var/mail) & print queues and outgoing mail queue (/var/spool)