The Linux directory structure can sometimes seem confusing, or complex, especially if coming from a Windows, Mac, or even a desktop Linux background where the details of such directories have either not been a concern, or abstracted away from us by the operating system.

This is a quick guide to what each of the common directories encountered in the Linux filesystem is intended for and what they contain.


/ - Root

The root directory, this is the directory that contains all other directories and files on the system.

/bin

Contains executables, many of the linux commands including ls, cp, touch and journalctl are stored here.

/boot

The /boot directory contains all of the files required by the Linux boot loader.

/dev

Stores all Linux device files such as hard disks, usb devices. stdin, stdout and stderr files are also located in the /dev directory.

/etc

Contains all the config files used by the system, files like crontab, fstab and ssh config files are all typically found here.

/home

Contains a home directory for each user. E.g. /home/lachlan. The ~ operator will reference the current users home directory.

For example a file test.txt in /home/lachlan could be accessed with ~/test.txt when logged in to the system as the user lachlan.

/lib

This directory contains libraries required by the binaries in /bin and /sbin. Some systems will have variants of this directory like /lib64 to support multiple versions of a library to support for example both 32 and 64-bit binaries.

/media

/media is a temporary mount point for removable devices. For example if a CD is inserted it will create a temporary folder here to provide access to the CD's contents.

/mnt

Another temporary mount point directory, similar to /media. /mnt is intended for system administrators to temporarily mount filesystems into however. An example of this would be mounting an external hard drive to recover some data from it.

/opt

Used for optional packages, typically any third party/proprietary software should be installed to this directory.

/proc

The /proc directory is for files relating to processes running on a system. Information that is stored here includes information relating to individual processes in a sub-directory named as the pid of the process. E.g. /proc/{pid}. Memory and CPU information is also stored here amongst a range of other things.

An interesting thing to note about the /proc directory is that the files and sub-directories are actually virtual files and don't really exist until they are accessed at which point the operating system creates the file on the fly. Before the information is stored in memory.

/root

This is the root users home directory, similar to regular users home directories in /home however it can only be accessed by the root user.

/sbin

The /sbin directory is very similar to the /bin directory, containing binaries for executable programs. /sbin is typically used to store system programs intended for administrators however. Examples include fdisk, iptables, and mdadm.

/srv

This is a directory that can be used to store files to be served, or relied upon by a particular service. Specific care should be taken in this directory when removing or updating files as services are likely dependant on them being here.

/sys

The /sys directory is similar to the /proc directory in the sense that it is a virtual filesystem. It contains virtual files relating to devices and device drivers. It's intended purpose is to expose hardware/firmware data and avoid polluting the /proc directory with such data.

/tmp

Stores temporary files created by both the system, and users. All files in this directory are deleted when Linux is rebooted so should not be considered safe for anything that needs to be persistent.

/usr

User installed programs will typically wind up here. There are a number of sub-directories in /usr such as bin, include, lib, and src. These contain things such as binaries for user programs such as git, htop, programming languages & runtimes such as Python, and compilers like gcc.

/var

Any variable files required by the system are typically stored here. They are stored in sub-directories including  log, mail, and spool. Things like log files, emails, and print queues are stored in these sub-directories.