Black Friday Deal - up to 36% OFF Choose Server

A Complete Guide to Understanding Linux File System Tree

November 14th, 2022
A Complete Guide to Understanding Linux File System Tree

Linux Filesystem follows a tree-like hierarchical layout that is governed by the Filesystem Hierarchy Standard (FHS). This is a standard maintained by the Linux Foundation. The latest version of the FHS at the time of writing this guide is version 3.0.3 which was released in June 2015.

The Linux Filesystem structure starts at the very top with the root directory which is the uppermost directory in the hierarchy. It contains all the directories and subdirectories on the system as we shall see later on in this guide.

To get a better picture of this, navigate to the root directory / and run the following command:

tree -D -L 1

List root directory tree

The output provides all the main directories residing on the system. Before we delve deeper and explore what each of these directories contain, let us briefly look at the main types of files on a Linux system.

Type of Files in Linux

In Linux and UNIX systems, everything is considered a file. If not, then it’s a running process. Generally, all files in Linux fall into either of these three categories.

  • Regular files: These include text files, photos, videos, programs, and executable files.
  • Directories: This might sound a bit strange, but in Linux, directories are also considered files since they provide storage for other files and subdirectories.
  • Special files: These are device files that comprise symbolic links, block files, socket files, and named pipe files.

That said, let us now examine the Linux File System Tree in more detail.

/ ( Root Directory)

Denoted by a single forward slash ( / ), the root directory is the topmost directory in the Linux hierarchy structure, as discussed earlier. All files and folders on your Linux system are stored here and can be referenced from this directory, even when stored in various locations such as removable or virtual devices.

List root directory

NOTE:

The root (/) directory is not to be confused with the root home directory ( /root ).

/home

The /home directory is a directory that contains users' personal files. The directory is the entry point for any login user on the Linux system. It stores folders, files, and personal data that is specific to an individual user.

Folders in the /home directory take the form /home/USERNAME where USERNAME is the name of the login user. For example, if we have a login user called mike, the home directory for the user will be /home/mike.

Inside the /home/USERNAME directory are other sub-directories such as Desktop, Downloads, Documents, Pictures, Videos, Templates, Public, and Music as below.

List home directory

In addition, home directories contain personalized configuration files which are hidden files preceded by a dot. Such files include the .bashrc, .bash_logout, and .bash_profile to mention a few. To view hidden files, run the ls command with the -la option as shown.

ls -la

List all in home directory

/root

This is the home directory of the root account, also known as the root user’s home directory. The /root directory stores configuration files for the root account in the same way each regular user's home directory contains configuration files and regular files for that user.

List root home directory

/boot

Another critical directory is the /boot directory. The directory, as the name implies, contains essential files needed to successfully boot the system. These files include the grub bootloader files, root filesystem files, Linux kernel files (vmlinuz), and other boot configuration files.

List boot directory

/bin

The /bin directory contains binary executables or Linux programs. These include common Linux commands that are made available for all users in single-user mode. These include cat, chown, chmod, ping, cp, mkdir, ls, cat, rm, and mv just to mention a few.

List bin directory

To confirm the path of a binary executable or command such as the cp command, run the command:

which cp

Check cp command path

/sbin

Unlike the /bin directory, the /sbin directory contains binary executables and command line tools that are preserved for the root user. These are privileged commands used for system administration tasks. Examples of such commands include fdisk, route, reboot, mkfs, init, and fsck to mention a few.

Again, to confirm the path to the binary executable, run the which command followed by the binary executable.

which reboot

Check reboot command path

/dev

The /dev directory contains special files that are representative of devices attached to the system. These include consoles, hard drives, or any other peripheral devices plugged into the system. A good example of a device file is /dev/sda which represents the first SATA hard drive attached to the Linux system.

The /dev directory is also a storage location for pseudo devices or virtual devices that do not reference any hardware connected to the system. An example is the /dev/null file which discards any data sent to it.

List dev directory

/etc

The /etc directory contains host-specific system-wide configuration files. It stores configuration files required by all programs as well as startup and shutdown shell scripts.

The configuration files can be modified using a text editor such as nano or vim by the root or sudo user which is a regular user with elevated privileges to run certain root commands.

List etc directory

/lib,/lib64

The /lib directory contains shared library images required in the /bin or /sbin directories. These are essential libraries required by the system to boot and run normally.

List lib directory

/media

The /media directory contains temporary sub-directories on which removable media such as optical drives are automatically mounted. A good example of a sub-directory is /media/cdrom for optical drives.

/mnt

The /mnt directory provides a temporary mount point on which removable media such as CDROMs can be mounted. It is most often used to mount storage devices or partitions manually, and is more of a relic of the past.

List mnt directory

/tmp

On Linux systems, temporary files are stored in the /tmp directory. These are temporary files created by the system and users. Files in this directory are usually a few kilobytes in size and are, in most cases, deleted when a system is rebooted.

List tmp directory

/opt

The /opt directory contains add-on applications or software packages that are provided by a third-party vendor and are not installed through your operating system package manager. Each such application has its own subdirectory which contains all the essential files needed for it to run.

When you install a software package from a third-party repository, or compile software binaries yourself, the files are stored in the /opt directory.

List opt directory

/var

Var stands for variable. As the name suggests the /var directory is a directory that contains files that are constantly changing in size such as log and spool files.

List var directory

Here is a list of the salient directories contained in the /var directory:

  • /var/log - Contains system and application log files.

  • /var/cache - Contains cached data from programs.

  • /var/mail - Contains users’ mailboxes

  • /var/spool - Comprises queued or spooled files for various programs.

  • /var/spool/cron - Contains spooled files for cron jobs.

  • /var/spool/at - Contains spooled jobs for at.

  • /var/spool/lpd - Contains spooled files for printing.

  • /var/opt - Contains variable data files for the /opt directory.

/run

Most Linux distributions come with the /run filesystem. This is a directory that stores volatile runtime data since the system was started. Data stored in this directory does not persist upon a reboot.

List run directory

/proc

Also referred to as the proc filesystem, The /proc directory is a virtual or pseudo filesystem that contains special files that provide information about running processes and the kernel’s current state. It is regarded as the information and control center of the Linux kernel.

The proc directory is a peculiar directory in that it’s not a real filesystem and it ceases to exist once the system is powered off. It is mounted at the /proc mount point during the booting process.

List proc directory

/usr

This is one of the most critical directories in the Linux system. The /usr directory is a directory that comprises libraries, binaries, and documentation for installed software applications. System files contained in this directory are shareable among other users.

List usr directory

At a glance, here are some of the salient subdirectories contained in the /usr directory:

  • /usr/bin- This contains binary files for user programs that cannot be found under the /bin directories. Examples of such programs include less, more, scp, and awk to mention a few.

  • /usr/sbin - This provides binary files for system administrators or privileged users. Usually, system binaries are located in the /sbin directory but if you can't find them there, look under the /sbin directory.

  • /usr/local - The directory contains user programs installed from source or outside the distribution's provided software. For example, when you install the Go programming language from source, it goes under the /usr/local/go directory.

  • /usr/lib - This provided libraries needed by the /usr/bin and /usr/sbin directories.

  • /usr/src- This contains the Linux header files, kernel sources, and documentation.

/srv (Service directory)

The term srv stands for service. The/srvdirectory contains site-specific data for your Linux distribution. It points to the location for data files for a specific service such as www, rsync, FTP and CVS.

/sys

This is a virtual or pseudo filesystem that contains a collection of virtual files that are attached to the Linux Kernel.

List sys directory

/snap

This is where snap packages go into. Snap is a package management system developed by Canonical, the publisher and maintainer of Ubuntu. Snaps are containerized, cross-distribution software packages that are packaged with all their dependencies. They are easy to install and are intended to work across all major Linux distributions that have snap enabled.

If you have installed an application from a snap package, then all the software files will be found in the /snap directory.

/lost+found

This is a directory that is mostly found in Ubuntu and Ubuntu-based distributions. It’s a special directory that contains obsoleted data. These are fragments of files that have either been deleted or lost during disk operation.

Conclusion

In this guide, we examined the Linux File System Tree and fleshed out the directories that make up the File system hierarchy. The Linux file filesystem hierarchy ensures consistency between various Linux Systems and provides Linux administrators and developers with a standard directory structure that makes it easy to manage the system.

Winnie is a seasoned Linux Systems administrator, currently specializing in writing technical Linux tutorials. With over seven years of experience in deploying and working with major Linux distributions such as Ubuntu, Debian, RHEL, OpenSUSE, and ArchLinux, she has written detailed and well-written "How to" Linux guides and tutorials. Winnie holds a Bachelor's Degree in Computer Science from Masinde Muliro University, Kenya and resides in Nairobi, Kenya. She is an expert in authoring Linux and DevOps topics involving Docker, Ansible, and Kubernetes. She currently works as a freelance technical writer and consultant. In her previous roles, she worked in the capacity of an IT support specialist and Linux administrator. Her key roles included offering level 1 and 2 support to both in-house and remote staff and managing and monitoring Linux servers.

Start Building Now

Deploy your new Cloud VPS server in 5 minutes starting from $5.83 / month.

We use cookies to ensure seamless user experience for our website. Required cookies - technical, functional and analytical - are set automatically. Please accept the use of targeted cookies to ensure the best marketing experience for your user journey. You may revoke your consent at any time through our Cookie Policy.
build: e51c8edd1.765