Introduction

The Linux directory structure is like a tree. The base of the Linux file system hierarchy begins at the root. The directory separator in Linux is symbolized by a forward slash ( / ).

Linux Directory Structure

The Common Top Level Directories

Here are the most common top level directories that you need to be aware of and may interact with as a normal user.

  • / - "Root" , the top of the file system hierarchy. Everythings start at root. If you hear someone say, look in slash or, that file is in slash, they are referring to the root directory.
    • /bin - Binaries and other executable programs. Programs are written in source code and this is human readable text. These text files are then complied into machine readable binaries. They are called binaries because machine code is a string of 0 and 1. Note: applications that you can run are sometimes located in /bin.
    • /etc - System configuration files. Configuration files control how the operating system or applications behave. For example, there is a configuration file in /etc that tell the operating system whether to boot into a text mode or a graphical mode.
    • /home - Home directories. Linux systems can and often do have multiple users and the home directory is where you can separate your data from another account's data. For example, a user robin's home directory is /home/robin. You could store documents, or music files, or pictures.
    • /opt - Optional or third party software. opt is for software that is not bundled with the operating system. For example, Google Earch is not part of the standard Linux operating system, so Google Earch get installed in opt.
    • /tmp - Temporary space, typically cleared on reboot. Most Linux distributions clear /tmp at boot time, therefore if you put files in /tmp and the Linux system gets rebooted, your file will be gone. /tmp is a great place to store temporary files, but do not put anyting in /tmp that you want to keep long term.
    • /usr - This is call User, where user related programs live.
    • /var - Variable data, most notably log files. Things that change often on a Linux system are typically log files that are generated either by the operating system itself or applications.

In Linux, people typically talk about directories. In other operating system people called the similar concept folders.

Comprehensive Directory List

  • / - "Root", the top of the file system hierarchy.
  • /bin - Binaries and other executable programs.
  • /boot - Files needed to boot the operating system.
  • /cdrom - Mount point for CD-ROMS.
  • /cgroup - Control Groups hierarchy.
  • /dev - Device files, typically controlled by the operating system and system administrators.
  • /etc - System configuration files.
  • /export - Shared file systems.
  • /home - Home directories.
  • /lib - System libraries.
  • /lib64 - System libraries, 64 bit.
  • /lost+found - Used by the file system to store recovered files after a file system check has been performed.
  • /media - Used to mount removable media like CD-ROMS.
  • /mnt - Used to mount external file systems.
  • /opt - Optional or third party software.
  • /proc - Provides info about running processes.
  • /root - The home directory for the root account.
  • /sbin - System administration binaries.
  • /selinux - Used to display information about SELinux.
  • /srv - Contains data which is served by the system.
  • /srv/www - Web server files.
  • /srv/ftp - FTP files.
  • /sys - Used to display and sometimes configure the devices known to the Linux kernel.
  • /tmp - Temporary space, typically cleared on reboot.
  • /usr - User related programs, libraries, and docs.
  • /usr/bin - Binaries and other executable programs.
  • /urs/lib - Libraries.
  • /usr/local - Locally installed software that is not part of the base operating system.
  • /usr/sbin - System administration binaries.
  • /var - Variable data, most notably log files.
  • /var/log - Log files.

Application Directory Structure

You will find that some applications that are not bundled with the linux operating system are installed in /usr/local/.
Example:

  • /usr/local/program_name/bin - the binary code for this program
  • /usr/local/program_name/etc - configuration file to config how the program behaves at runtime
  • /usr/local/program_name/lib - program related libraries.
  • /usr/local/program_name/log - the log files that this program is generating.

In addtion, we already mentioned about how applications can be installed in /opt. Here is the common pattern:
Example:

  • /opt/program_name/bin - the binary code for this program
  • /opt/program_name/etc - configuration file to config how the program behaves at runtime
  • /opt/program_name/lib - program related libraries.
  • /opt/program_name/log - the log files that this program is generating.

Moreover, here is a slight variation that you will sometimes see applications follow:
Example:

  • /etc/opt/program_name - configuration files.
  • /opt/program_name/bin - main program_name program gets installed here.
  • /opt/program_name/lib - program related libraries.
  • /var/opt/program_name - the log files.

Sometimes, applications get installed, they're not given their own directory structure. They are installed in a shared manner.
Example:

  • /usr/local/bin/program_name
  • /usr/local/etc/program_name.conf
  • /usr/local/lib/libprogram_name.so

Another variation is opt/company_name/product_name
Example:

  • /opt/google
  • /opt/google/chrome
  • /opt/google/earth