Using Linux

Using Linux: Understanding the Linux Directory Structure

If you’re coming from Windows, the Linux file system structure can seem particularly alien. The C:\ drive and drive letters are gone, replaced by a forward slash “/” and some various cryptic-sounding directories, most of which have three letter names. The whole system can be a bit confusing and frustrating, so I’ve composed this article which will hopefully clear up some of the obscurity behind the Linux directory structure and shed new light on how it works and what it all means.

Introduction

If you would like to bypass any simplification and just jump head first into the technicals, you can go straight to the Filesystem Hierarchy Standard (FHS) which exhaustively defines the structure of file systems on Linux and other UNIX-like operating systems. You can access the FHS here: http://www.pathname.com/fhs/pub/fhs-2.3.html

A quick note of attributions and sources: The content of this article was adapted from a few different sources of information, namely the Filesystem Hierarchy Standard (mentioned above) and the HowToGeek article found here: http://www.howtogeek.com/117435/htg-explains-the-linux-directory-structure-explained/

Alright, lets get started…


Overview

Here is a quick-reference list which contains all of the directories described in this article:

  • ( / ) – The Root Directory
  • ( /bin ) – Essential User Binaries
  • ( /boot ) – Static Boot Files
  • ( /cdrom ) – Historical CD-ROM Files
  • ( /dev ) – Device Files
  • ( /etc ) – Configuration Files
  • ( /home ) – Home Folders
  • ( /lib ) – Essential Shared Libraries
  • ( /lost+found ) – Recovered Files
  • ( /media ) – Removable Media
  • ( /mnt ) – Temporary Mount Points
  • ( /opt ) – Optional Packages
  • ( /proc ) – Kernel & Process Files
  • ( /root ) – Root Home Directory
  • ( /run ) – Application State Files
  • ( /sbin ) – System Administration Binaries
  • ( /selinux ) – SELinux Virtual File System
  • ( /srv ) – Service Data
  • ( /tmp ) – Temporary Files
  • ( /usr ) – User Binaries & Read-Only Data
  • ( /var ) – Variable Data Files

Linux Directories


/ – The Root Directory

Linux Directory root

Everything on the Linux system is located under the / directory, known as the root directory. You can think of the / directory as being similar to the C:\ directory on Windows – but this isn’t strictly true, as Linux doesn’t have drive letters. While another partition would be located at D:\ on Windows, this other partition would appear in another folder under / on Linux.


/bin – Essential User Binaries

Linux Directory bin

The /bin directory contains the essential user binaries (programs) which must be available when the system is mounted in single-user mode. Applications such as Firefox are stored in /usr/bin, while important system programs and utilities such as the bash shell are located in /bin. The /usr directory may be stored on another partition – placing these files in the /bin directory ensures the system will have these important utilities even if no other file systems are mounted. The /sbin directory is similar – it contains essential system administration binaries.


/boot – Static Boot Files

Linux Directory boot

The /boot directory contains the files needed to boot the system – for example, the GRUB boot loader’s files and your Linux kernels are stored here. The boot loader’s configuration files aren’t located here, though – they’re in /etc with the other configuration files.


/cdrom – Historical CD-ROMs

Linux Directory cdrom

The /cdrom directory isn’t part of the FHS standard, but you’ll still find it on Ubuntu and other operating systems. It’s a temporary location for CD-ROMs inserted in the system. However, the standard location for temporary media is inside the /media directory.


/dev – Device Files

Linux Directory dev

Linux exposes devices as files, and the /dev directory contains a number of special files that represent devices. These are not actual files as we know them, but they appear as files – for example, /dev/sda represents the first SATA drive in the system. If you wanted to partition it, you could start a partition editor and tell it to edit /dev/sda.

This directory also contains pseudo-devices, which are virtual devices that don’t actually correspond to hardware. For example, /dev/random produces random numbers. /dev/null is a special device that produces no output and automatically discards all input – when you pipe the output of a command to /dev/null, you discard it.


/etc – Configuration Files

Linux Directory etc

The /etc directory contains configuration files, which can generally be edited by hand in a text editor. Note that the /etc/ directory contains system-wide configuration files – user-specific configuration files are located in each user’s home directory.


/home – Home Folders

Linux Directory home

The /home directory contains a home folder for each user. For example, if your user name is bob, you have a home folder located at /home/bob. 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 and must obtain elevated permissions (become the root user) to modify other files on the system.


/lib – Essential Shared Libraries

Linux Directory lib

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

Linux Directory lostandfound

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. Please note that you are unable to browse the contents of the lost+found directory without having root privileges.


/media – Removable Media

Linux Directory media

The /media directory contains subdirectories for each system user where removable media devices inserted into the computer are mounted. For example, when you insert a USB drive into your Linux system, a directory will automatically be created inside the /media directory. You can access the contents of the USB inside this directory.


/mnt – Temporary Mount Points

Linux Directory mnt

Historically speaking, the /mnt directory is where system administrators mounted temporary file systems while using them. For example, if you’re mounting a Windows partition to perform some file recovery operations, you might mount it at /mnt/windows. However, you can mount other file systems anywhere on the system.


/opt – Optional Packages

Linux Directory opt

The /opt directory contains subdirectories for optional software packages. It’s commonly used by proprietary software that doesn’t obey the standard file system hierarchy – for example, a proprietary program might dump its files in /opt/application when you install it.


/proc – Kernel & Process Files

Linux Directory proc

The /proc directory similar to the /dev directory because it doesn’t contain standard files. It contains special files that represent system and process information.


/root – Root Home Directory

Linux Directory root

The /root directory is the home directory of the root user. Instead of being located at /home/root, it’s located at /root. This is distinct from /, which is the system root directory. Please note that you are unable to browse the contents of the /root directory without having root privileges.


/run – Application State Files

Linux Directory run

The /run directory is fairly new, and gives applications a standard place to store transient files they require like sockets and process IDs. These files can’t be stored in /tmp because files in /tmp may be deleted.


/sbin – System Administration Binaries

Linux Directory sbin

The /sbin directory is similar to the /bin directory. It contains essential binaries that are generally intended to be run by the root user for system administration.


/selinux – SELinux Virtual File System

If your Linux distribution uses SELinux for security (Fedora and Red Hat, for example), the /selinux directory contains special files used by SELinux. It’s similar to /proc.

Ubuntu doesn’t use SELinux, so the presence of this folder on several Ubuntu editions up until recently was nothing more than a harmless system bug.


/srv – Service Data

Linux Directory srv

The /srv directory contains “data for services provided by the system.” If you were using the Apache HTTP server to serve a website, you’d likely store the live files which make up the components of your website inside of a directory that is located inside the /srv directory.


/tmp – Temporary Files

Linux Directory tmp

Applications store temporary files in the /tmp directory. These files are generally deleted whenever your system is restarted and may be deleted at any time by utilities such as tmpwatch or tmpreaper.


/usr – User Binaries & Read-Only Data

Linux Directory usr

The /usr directory contains applications and files used by users, as opposed to applications and files used by the system. For example, non-essential applications are located inside the /usr/bin directory instead of the /bin directory and non-essential system administration binaries are located in the /usr/sbin directory instead of the /sbin directory. Libraries for each are located inside the /usr/lib directory. The /usr directory also contains other directories – for example, architecture-independent files like graphics are located in /usr/share.

The /usr/local directory is where locally compiled applications install to by default – this prevents them from bogging down the rest of the system with non-essential files and directories.


/var – Variable Data Files

Linux Directory var

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.


Conclusion

I hope that this quick overview has been of use to anyone who needs the information. If you would like to check out any of my other Linux/Ubuntu related tutorials, you can find a few of them at the following locations:

Using Linux: Viewing All Active Processes & Programs

Using Linux: Exploring System Hardware

Using Linux: Setting Up Removable Swap Space

etc…

 

Published by

willinspire

Entrepreneur Cryptocurrency Trader Forex Trader Internationally Published Model Model Coach, Model Scout Published Photographer USMC Veteran Violinist and Pianist Investor Visionary

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s