Linux Directory Structure/Filesystem Explained

Table of Content

  1. Overview
  2. Differences Between Linux and Microsoft Windows File System
  3. Linux Directories
    1. /bin - User binaries
    2. /sbin - System binaries
    3. /boot - Boot loader files
    4. /cdrom - Mounting point for CD-ROM or DVD Drives
    5. /dev - Device files
    6. /etc - Location for configuration files and startup scripts
    7. /home - User's personal folder
    8. /lib, /lib32, /lib6 - Shared application library files
    9. /lost+found - Orphaned files
    10. /media - Mounting point for external storage devices
    11. /mnt - Temporary manual mounting point for system administrators
    12. /opt - Optional location for application files
    13. /proc - Contains information about the system and running processes
    14. /root - Home directory for the root user
    15. /run - Used by applications or system processes to store temporary data
    16. /srv - Contains data and files specific to web, FTP, and similar servers
    17. /sys - Location for system configuration, hardware, and operating system information
    18. /tmp - Temporary storage
    19. /usr - Stores user application and utilities
    20. /var - Contains variable data such as system logs, cache files, and spool data.
Terminal listing of Linux directories.

Overview

If you are new to the Linux operating system, its file structure can be intimidating to navigate, even for a seasoned Windows administrator. Although each developer of a Linux operating system (distro) can customize their distribution’s folder structure, most follow the Filesystem Hierarchy Standard (FHS) maintained by the Linux Foundation. Based on the Unix file system, it establishes the convention for the folder structure used in Linux. The first version of the FHS was released on February 14, 1994 and has evolved ever since to version 3 released on May 18, 2015.


Differences Between Linux and Microsoft Windows File System

Before describing the various directories in a Linux file system, there are some important factors to note - particularly for someone that has worked in a Windows environment for a period of time. While there are obviously more differences between Linux and Windows than what is listed here, for the purposes of this article, the following is worth noting.

  • Forward Slash - Unlike Windows, since Linux it is based on Unix, it uses the forward slash in their folder path. Such as ‘/var/www/’ in Linux and ‘Windows\system32’ in Windows
  • Folder versus Directory - While there is a subtle difference between the two terms, Linux (and other Unix-based operating systems) uses the term 'directory' to refer to the structure used to organize files. For the purpose of this article, we will use them interchangeably here.
  • Case-Sensitive Filenames - Unlike the Windows operating system, filenames in Linux are case-sensitive. For example, a list of files with the following filenames are all unique files and co-exist in the same folder in a Linux system:
    • filename.txt
    • FILENAME.txt
    • fileNAME.txt
    • FileName.txt
    • fiLeNaMe.txt
  • Drive Letters - Windows make use of drive letters to identify a specific physical or logical hard drive. In Linux, there is no such thing. Instead, the drive is mounted under the root directory and is then references using a naming scheme. For example, to access the second partition (2) of the second (b) IDE hard disk, you use '/dev/hdb2'.
  • Administrator Account - In Windows, you can specify a number of users to have administrative-level privileges. However, in Linux, there is only one account, the root user, that is the ‘super-user’ and has all the administrative privileges,

Common Linux Directories

  • /bin - The /bin (binaries) directory is where essential system programs or applications (binary, non-text files) are stored. Typically, it contains the programs (executable commands) a typical Linux user would use. These include the ls command to list files and directories (aka, folders), cp to copy files or folders, or cd to change directory. It's worth noting that user applications are not stored here but in the /usr directory.
  • /sbin - Like /bin, this directory also contains system programs. However, the programs are for Linux system administrators (root-privileged users/superuser) and, unless given explicit permission, a typical user would not have access to them. Programs in this directory are primarily used to configure the system or to perform system maintenance, such as fsck, ifconfig, and route.
  • /boot - This is a critical directory that contains the boot loader files needed by Linux to successfully start up the system.
  • /cdrom - This is a legacy directory and was used as the mounting point for a system that has a CD-ROM or DVD drive. You may find that some latest Linux distributions lack this folder as small and convenient flash drives and other portable storage media are more commonplace. In these distros, mounted CDs and DVDs would appear in the /media directory.
  • /dev - This directory, short for devices, is where you or an application interacts with physical or virtual devices at a system level. With the exception of network adapters, each device such as your keyboard, webcam, or a hard drive, is represented in this directory as a file and is created dynamically.
  • /etc - Pronounced et-see and short for et cetera, this directory contains various system-wide configuration files and startup scripts. As a Linux administrator, you may often find yourself working in this directory to edit config files for your FTP service, SSH setup, message of the day (MOTD), permitted network connections (hosts.allow or host.deny files) and various security settings. It’s worth noting that users’ specific settings, such as their LibreOffice settings, are not saved in this folder, but instead are saved in a configuration file within the user’s folder.
  • /home - This directory is where each user’s (excluding the root user - see /root) personal home folder is stored. Unless using a privileged account, each user can only access the content of their own directory. Each user has their own respective folder in this directory and is used to store their personal files. Additionally, a user’s personalized settings for their applications (such as LibreOffice) are also stored here - automatically by the application itself.
  • /lib, /lib32, /lib64 - These contain kernal modules and shared library files your applications use to perform common or specific functions.
  • /lost+found - This directory is used by Linux to store orphaned files - such as those caused by a system crash or discovered through a hard drive utility such as the fsck command.
  • /media - This directory is the mounting point for Linux to automatically mount removable media, such as a floppy disk, network drive, USB flash drive or hard drive.
  • /mnt - Short for mount, this is similar to the /media directory, however, it serves as a temporary mounting point for system administrators to manually mount a storage media. You typically would not want to manually mount a device to the /media directory as it is a directory managed by the operating system. This is not commonly used nowadays.
  • /opt - Short for optional, this directory is where third-party applications can install add-on components. This is a legacy directory and is currently being maintained for compatibility reasons.
  • /proc - Short for process, this directory contains a “file” for every running process in your system. It is a pseudo file system (virtual file system) that exists only in memory and special “files” are automatically created at system start up, continually updated as your system runs, and are then deleted at shutdown. Although displayed with a zero file size, these files contain a plethora of information about your CPU, memory, and all the processes running on the system. A system administrator or a developer will access the information, either directly or through an application, to monitor the system or a process, to troubleshoot a problem, or perform a variety of other administrative tasks. However, caution should be taken when making changes to the /proc directory as it can cause system instability or crash.
  • /root - This is the home directory of the root user. Unlike a typical user’s home directory, the location of the root user’s home directory is stored in the root directory. This ensures the root user will always have access to their home directory in the event the regular user's home directory is stored in another drive which the root user may not have access to at the time.
  • /run - The run directory contains information about your system and applications since it was booted (run-time data). Information such as logged-in users and data programs (daemons) need to run is maintained here. Similar to the /process directory, it is a temporary filesystem and content is cleared when the system shuts down.
  • /srv - Short for servers, this is where files related to specific server services are stored. For example, for a Linux web server, HTML web page files may be stored in /srv/http/www. Where for an FTP server, files may be stored in /srv/ftp.
  • /sys - Similarly to /proc, it contains various information on system configurations, hardware information, and system-level programs and is managed by the kernel - the core component of the Linux operating system and manages the CPU, memory and other devices. System administrators will often gather information from this and the /proc directory for maintenance and troubleshooting.
  • /tmp - As its name suggests, this directory is where temporary files are stored. Files you may have downloaded or auto-saved copy of your word processor documents can be found here.
  • /usr - Although sometimes incorrectly interrupted as a directory of users, this folder is where most user applications and utilities are stored. It is typically accessible, not but editable unless you are a root user, by all users. This directory was however, in the early Unix days, where user’s home directories were stored. Today, most modern Linux distros store user’s home directories in the /home directory.
  • /var - Short for variable, this directory contains a variety of information. It can contain log data (/var/log), email support (/var/qmail), cache files, pending jobs or tasks (/var/spool), web site files (/var/www), MySQL databases (/var/lib/mysql), and more.


Suggestion

It truly is a BIBLE on Linux.

Amazon Reviewer


Buy from Amazon

Suggestion

A Treasure Trove of Technical Instruction and Reference Material

Amazon Reviewer


Buy from Amazon

Suggestion

If you forget a command this is great

Amazon Reviewer


Buy from Amazon