
The Linux operating system is based on UNIX and shares its base directory structure. The Filesystem Hierarchy Standard (FHS)1 is followed by most distributions and helps ensure the various distributions and forks remain largely consistent. This consistency simplifies software installation, provides a degree of predictability for system administrators, and helps with troubleshooting.
Root directory
/
The root directory is the starting point for the filesystem where everything else is structured inside or beneath this directory. Even if files are stored on different physical or virtual media, they will be placed under the root directory. An absolute path starts at root and lists the full path to the file or directory.
Example:
- /home/user1/file1
- /var/log/auth.log
Binaries directory
/bin
The bin directory contains the basic binaries for standard shell operations as well as critical binaries for system boot and repair2. These are usually available to all users of the system.
No sub-directories inside this directory.
Boot files directory
/boot
The boot directory contains everything required for the boot process except configuration files not required at boot time and the map installer3. Think boot loader.
Devices directory
/dev
The dev directory contains virtual files that represent devices and disks and special files.
Examples:
- /dev/sda1
- /dev/null
- /dev/tty
Configuration directory
/etc
The etc directory contains system configuration files used mainly by services and administrators. A configuration file controls the operation of a program and must be a static file. No binaries can be stored here.
In general, files are stored in sub-directories rather than in the top level directory.
Fun fact
The name of this directory is somehow the source of some controversy. No, I don’t get it either.
/etc/opt
This sub-directory stores configuration files for optional software in the /opt directory, organised into sub-directories.
Home directory
/home
The home directory contains user directories and user specific configuration files. Users store their personal files in their assigned directory. Users generally don’t have access to other users’ directories.
Shared libraries directory
/lib
The lib directory holds shared libraries used during boot and by the binaries in bin and sbin.
Removable media
/media
The media directory is where removable media devices are mounted when connected to the system.
Examples:
Mount directory
/mnt
The mnt directory is where an administrator can mount a device or filesystem, usually temporarily. Unlike media, items in this directory are all manually mounted.
Optional software directory
/opt
The opt directory is used for installing software from outside standard repositories.
Processes directory
/proc
The proc directory is a virtual filesystem that contains information about currently running processes and kernel parameters. It is automatically generated by the system, on the fly.
Root home directory
/root
This is the home directory of the root user. Don’t confuse it with the root directory.
Runtime variable directory
/run
The run directory contains system data describing the system since boot (currently logged-in users and running daemons7). All files in this directory will be cleared on restart.
Historically, this directory was /var/run and some applications still use the old location.
System binaries
/sbin
The sbin directory, like bin, contains binary files for system operations8. These are only for the root user or users with sudo privileges, however.
Services directory
/srv
The srv directory contains site specific data for services provided by the system.
Examples:
- Web servers
- FTP servers
Temporary directory
/tmp
The tmp directory is a temporary storage location that can be used by applications or users. It is emptied on each restart, and some distributions clear out older files automatically. It may also be size limited.
Nothing important should be stored here.
User binaries and configurations directory
/usr
The usr directory contains the majority of system-wide executables, libraries, and most system programs. Files here are read-only and shareable.
Historically, this was also where a user home directories were stored. Some modern systems also use symlinks for the /bin, /sbin, and /lib directories to the equivalent directories in the /usr directory.
/usr/bin
This sub-directory contains non-essential9 binaries for most users.
No sub-directories inside this directory.
/usr/include
This sub-directory contains the general use C include files for the system.
/usr/lib
This sub-directory contains object files and libraries for binaries in the /usr/bin and /usr/sbin directories.
/usr/local
This sub-directory is for use by administrators when installing software locally. It contains more sub-directories.
/usr/sbin
This sub-directory is for non-essential system binaries used by the administrator such as network daemons.
No sub-directories inside this directory.
/usr/share
This sub-directory is where software will store data that it needs but doesn’t need to be modified10. Applications will use their own sub-directory to store multiple files, or if they use only one may use /usr/share/misc.
Variables directory
/var
The var directory holds system and application runtime information. This includes spool directories and files, administrative and logging data, and temporary files.
This directory is a counterpoint to the usr directory which is now read-only.
/var/cache
This sub-directory stores application cache data.
/var/lib
This sub-directory stores application and system state information. It is persistent data modified by programs as they run. This is used to maintain the state of an application between calls or across different instances.
/var/lock
This sub-directory stores lock files11 for devices or shared resources.
/var/log
This sub-directory contains miscellaneous log files.
/var/opt
This sub-directory is for applications in the opt directory to store their variable data.
/var/run
This sub-directory was to store system data describing the system since boot but is being phased out for /run. Still exists for compatibility reasons.
/var/spool
This sub-directory contains spool12 data awaiting processing.
/var/tmp
This sub-directory is for applications that need to store temporary data or directories that persist past a system reboot.
- Latest Filesystem Hierarchy Standard version. ↩︎
- The FHS defines a minimum set of binaries to be included. ↩︎
- The map installer is a historical reference to when LILO was the standard Linux boot loader (as of 2010 most distributions have switched to GRUB). See this reference to learn more about LILO. ↩︎
- A floppy disk was a form of magnetic storage media—a circular magnetic film encased in a square plastic shell (to keep dust out). It is an image of the floppy disk that is the origin of the ‘save’ symbol. ↩︎
- A CD-ROM (Compact Disk Read Only Memory) is a circular optical disk that stores data in a non-editable format. They were used to distribute software in the late 1990s and early 2000s. ↩︎
- A zip drive is a removable cartridge used to store ‘large’ amounts of data. It was used between the eras of floppy disks and CD-ROMs. ↩︎
- A daemon is a program that runs in the background. ↩︎
- The FHS defines a minimum set of binaries to be included. ↩︎
- Non-essential here means not required for boot, diagnosis, and repair of the operating system. ↩︎
- The more formal definition is that the /usr/share directory is the hierarchy for architecture-independent shareable text files. ↩︎
- Lock files are used in Linux to coordinate access to shared resources to prevent conflict and ensure integrity. See this reference for more information. ↩︎
- Spool (Simultaneous Peripheral Operations On-Line) data allows a program to hand off data quickly to an intermediate storage area, freeing it to continue other work while another process handles the queued data. Essentially, this is a queue of data awaiting processing. ↩︎