Linux online course

Linux File System Structure and the Filesystem Hierarchy Standard

Learn how Linux organizes files under /, use absolute and relative paths, navigate with pwd, ls, and cd, and understand common directories, mounts, devices, permissions, and FHS conventions.

Linux organizes files and many other resources in a single tree called the filesystem hierarchy. The top of this tree is the root directory, written as /. Every path begins at or can ultimately be reached beneath this directory, including filesystems mounted from other disks, partitions, network shares, or removable devices.

This is different from the root user. The root directory is a location in the filesystem; the root user is the administrative superuser account.

The unified Linux filesystem hierarchy

Linux presents regular files, directories, device interfaces, and several kernel-provided resources through one directory-tree structure. A separate filesystem does not create a second unrelated tree for users to navigate. Instead, it is attached to an existing directory through a mount point.

For example, a system might have one filesystem mounted at / and another mounted at /home. Users still reach personal files with paths such as /home/alex/notes.txt. The contents of the filesystem mounted at /home appear beneath that directory.

Files, directories, and special files

Regular files

A regular file stores data. Examples include text documents, program binaries, images, shell scripts, and configuration files. A regular file can have permissions, an owner, a size, and timestamps.

Directories

A directory is a filesystem object that organizes names for files and subdirectories. It does not simply contain a text list in the way a spreadsheet does; the filesystem maintains directory entries that map names to objects.

Special files

Linux also supports special file types. A symbolic link stores another pathname and redirects access to that pathname. A device node provides a file-like interface to a device or kernel-managed resource. A socket enables communication between processes, and a named pipe provides a filesystem name for a stream used between processes.

When people say that Linux treats many resources as files, they mean that common file operations and pathnames provide a consistent interface to resources such as terminals, devices, process information, and kernel settings. This does not mean every resource is stored as ordinary data on a disk.

Common filesystem object types

Object typeLong-listing indicatorPurposeExample
Regular file-Stores ordinary data/etc/hosts
DirectorydOrganizes names for objects/var/log
Symbolic linklPoints to another pathname/bin on some usr-merged systems
Block devicebProvides block-oriented storage access/dev/sda
Character devicecProvides stream-oriented device access/dev/tty
SocketsSupports process communicationA service socket beneath /run
Named pipepProvides a named one-way data streamA FIFO created by an application

Pathnames and paths

A pathname, or path, is a sequence of directory names followed by the name of a filesystem object. The slash character separates components. For example, /home/alex/projects/app.py identifies app.py inside projects, inside alex, inside home.

Absolute paths

An absolute path begins with /. It is interpreted from the root directory, regardless of the shell's current location. For example, /etc/hosts identifies the same object no matter which directory the shell is using.

Relative paths

A relative path does not begin with /. The shell and programs interpret it from the current working directory. If the current directory is /home/bob, then file.txt means /home/bob/file.txt.

The path ./file.txt means the same thing in that situation. The component . means the current directory, while .. means the parent directory. The tilde ~ is shell shorthand for the current user's home directory. The hyphen used as cd - means the shell's previous working directory.

Form or symbolMeaningExampleResolution context
/Root directoryls /Top of the hierarchy
Absolute pathPath resolved from root/home/bob/file.txtIndependent of current directory
Relative pathPath resolved from the current directoryfile.txtDepends on current directory
.Current directory./script.shCurrent directory
..Parent directory../sharedParent of current directory
~Current user's home directory~/DownloadsExpanded by the shell
-Previous directory for cdcd -Shell navigation history

Current working directory and navigation

Every shell session has a current working directory. Commands use this directory when resolving relative paths. The command pwd prints it, ls lists entries, and cd changes it.

pwd
ls
ls /
cd /home/bob
pwd
cd ..
cd ~
cd -

cd / moves directly to the root directory. cd .. moves to the parent of the current directory. cd ~ moves to the current user's home directory. cd - returns to the directory used before the most recent directory change.

For example, when the current directory is /home/bob, both file.txt and ./file.txt refer to /home/bob/file.txt. From /var, the same relative path refers to /var/file.txt instead.

cd /home/bob && pwd
ls -ld / /home /etc /usr /var /dev

Filesystem Hierarchy Standard

The Filesystem Hierarchy Standard (FHS) is a convention describing the intended purposes and usual locations of directories in Linux-like systems. It helps administrators and software developers predict where configuration, programs, logs, libraries, and user data are normally placed.

Distributions generally follow these conventions, but details vary. A directory's intended purpose does not guarantee that every installation has the same files, subdirectories, packages, or mount layout. Desktop, server, container, embedded, and distribution-specific systems can all differ.

Common Linux top-level directories

DirectoryPrimary purposeTypical contentsNotes and modern variations
/Root of the hierarchyTop-level directories such as /etc, /usr, and /varAll accessible mounted locations are reached beneath it
/binEssential user command binariesBasic commands traditionally needed for normal use and recoveryOften merged with or symbolically linked to /usr/bin
/bootBoot-related filesBootloader files, kernel images, and initial RAM filesystem imagesMay be a separate filesystem
/devDevice nodes and kernel interfacesDisks, terminals, null devices, and other device entriesUsually populated dynamically
/etcSystem-wide configurationService settings, account databases, networking configurationConfiguration is generally text-based, but formats vary
/homeRegular users' home directories/home/alex, /home/bobConventional; administrators can configure another location
/lib and /lib64Essential shared libraries and kernel modulesRuntime libraries and modules needed by core programsMay be merged into /usr/lib; /lib64 is architecture-dependent
/mediaRemovable-media mount pointsUSB drives, optical media, and similar devicesCommon on desktop systems; layout is configurable
/mntTemporary manual mount pointA filesystem mounted for short-term administrationOften used for manually mounted storage
/optOptional application softwareThird-party or self-contained application packagesUsage differs by vendor and distribution
/procKernel and process informationProcess directories and kernel status or configuration interfacesA virtual filesystem, not ordinary disk storage
/rootRoot user's home directoryAdministrative user's personal files and shell configurationDistinct from the root directory /
/runRuntime data created since bootProcess IDs, sockets, locks, and service stateUsually temporary and recreated during boot
/sbinEssential system-administration commandsCommands traditionally used for system maintenanceOften merged with or linked to /usr/sbin
/srvData served by system servicesPossible web, file-transfer, or repository dataOptional; service-specific layouts are common
/sysKernel device and system informationDevice, driver, bus, and kernel attribute interfacesA virtual filesystem generated by the kernel
/tmpTemporary storageShort-lived files created by users and programsContents may be cleaned automatically
/usrMajor user-space software hierarchyPrograms, libraries, documentation, and shared read-only dataOften treated as relatively stable; it contains /usr/bin and /usr/share
/varVariable system and application dataLogs, caches, databases, spool files, and stateCan grow substantially and may be a separate filesystem

Important subdirectories

  • /usr/bin: Common user-space command binaries.
  • /usr/sbin: System-administration and service-management commands.
  • /usr/lib: Shared libraries, program support files, and architecture-specific components.
  • /usr/local: Software and data installed locally by an administrator rather than normally managed by the distribution package system.
  • /usr/share: Architecture-independent data such as documentation, locale data, icons, and manuals.
  • /var/log: System and application logs.
  • /var/tmp: Temporary files that are generally intended to survive a reboot longer than files in /tmp, although cleanup policies vary.
  • /var/cache: Reusable cached data that programs can usually regenerate.
  • /var/lib: Persistent application and system state, such as package databases or service databases.
  • /var/spool: Queued work, including print jobs, mail queues, and scheduled-job data.
  • /proc and /sys: Virtual filesystem interfaces exposing process, kernel, device, and system information.
  • /lost+found: A recovery directory that may appear at the top of ext-family filesystems after filesystem creation or repair.

Device files in /dev

A device node is a special file, normally located in /dev, that gives programs a file-like interface to a hardware device or kernel-managed resource. A block device transfers data in blocks and commonly represents a disk or partition. A character device transfers data as a stream of characters, as with a terminal.

  • /dev/sda is a traditional name for a storage device.
  • /dev/nvme0n1 is an example of an NVMe storage device name.
  • /dev/tty represents the controlling terminal interface.
  • /dev/null discards data written to it and reports end-of-file when read.
  • /dev/zero supplies zero bytes when read.
  • /dev/random provides random data through a kernel interface.
ls -l /dev/null /dev/zero

Mount points and multiple filesystems

A disk, partition, network share, or removable device contains a filesystem that can be attached to the directory tree. The directory where it is attached is the mount point. After mounting, the filesystem's contents appear at that path.

The root filesystem is mounted at /, but /home, /boot, or a removable-media directory may each be a separate filesystem. A mount hides the directory's previous contents while the mount is active; those original contents become visible again when the filesystem is unmounted.

findmnt
df -hT

findmnt displays the mounted filesystem tree and mount points. df -hT reports filesystem capacity, filesystem type, and mount location. These commands are useful when expected files are missing or when checking whether a directory is a separate filesystem.

Permissions and directory access

Filesystem objects have an owner, a group, and permissions. The basic permission categories are read, write, and execute, applied separately to the owner, group, and others.

For a regular file, read permits reading content, write permits modification, and execute permits execution when the file is otherwise suitable. For a directory, read permits listing names, write permits creating or removing entries, and execute permits traversal through the directory and access to objects beneath it. Therefore, a user may see a directory but still receive a permission error when entering it or accessing a particular file.

ls -ld /etc /var/log /home
stat /etc /var/log

Permission errors commonly occur when a user attempts to list, enter, create files in, or modify administrative directories without the required permissions. Inspect the path, ownership, and permission bits before deciding whether administrative access is appropriate.

Modern distribution variations and usr merge

Many current systems use usr merge. In this layout, traditional directories such as /bin, /sbin, and /lib may be symbolic links to corresponding locations beneath /usr, such as /usr/bin, /usr/sbin, and /usr/lib. Other systems may use directories that are operationally unified in a different way.

ls -ld /bin /usr/bin /sbin /usr/sbin
readlink -f /bin
stat /bin /usr/bin

Seeing the same commands through /bin and /usr/bin is normal on a usr-merged system. Likewise, /home and /media are conventions, not unchangeable requirements. Containers, servers, embedded systems, and different distributions can have different contents or omit directories that are unnecessary for their role.

Practical inspection exercises

Inspect the root hierarchy

ls /
ls -ld / /home /etc /usr /var /dev

Identify familiar entries such as etc, home, usr, var, dev, and tmp. The exact list depends on the system.

Compare file types

ls -l /dev/null /dev/zero
ls -l /path/to/regular-file /path/to/symbolic-link

The first character in a long listing indicates the object type: - for a regular file, d for a directory, l for a symbolic link, b for a block device, and c for a character device. Use an available regular file and symbolic link when the example paths do not exist on your system. For another method of identifying file types, see Determine File Type.

Compare stable configuration and changing data

ls /etc
ls /var/log

/etc primarily contains system-wide configuration, while /var/log contains changing records produced by the system and applications. Access to logs may require appropriate group membership or administrative privileges.

Troubleshooting path and filesystem problems

cd: No such file or directory

  • Check the current location with pwd.
  • Check the parent directory with ls or ls path-to-parent.
  • Look for misspelled path components.
  • Try the intended absolute path.
  • Check whether the expected filesystem is mounted with findmnt or df -hT.

Permission denied

  • Inspect the directory with ls -ld PATH.
  • Check its owner, group, and permission bits.
  • Remember that directory execute permission controls traversal.
  • Do not bypass permissions unless administrative access is appropriate for the task.

Expected files are missing beneath a mount point

The filesystem might not be mounted, or another filesystem might be mounted over the directory and hiding its original contents. Run findmnt TARGET or df -hT, check the intended mount configuration, and verify that the path matches the conventions used by the distribution.

A device path does not exist

Do not assume every disk is named /dev/sda. Systems may use names such as /dev/nvme0n1 or /dev/vda.

ls /dev
lsblk

Use the available device listings and lsblk to inspect recognized block devices. A missing entry can also indicate undetected or unavailable hardware.

Exam-relevant distinctions

  • / versus /root: / is the root directory; /root is the root user's home directory.
  • Absolute versus relative: an absolute path begins with /; a relative path depends on the current working directory.
  • /etc versus /var: /etc holds system configuration; /var holds changing data such as logs and caches.
  • /tmp versus /var/tmp: both hold temporary data, but cleanup and expected persistence differ by policy.
  • /dev: contains device nodes, not ordinary copies of hardware data.
  • /proc and /sys: are virtual filesystems generated by the kernel.
  • FHS: defines conventional purposes, not an identical mandatory directory listing on every Linux installation.
  • usr merge: /bin, /sbin, and /lib may point into /usr.

For further shell context, review Bourne Again Shell Bash, and for command lookup behavior see Show The Full Path Of Shell Commands. The broader Linux topic index is available at Linux.