The file system structure on most Linux distributions is loosely based on something called the Filesystem Hierarchy Standard which guides the usage of the various root directories. This article was created to help beginner Linux users with a "cheat sheet" of the most common Linux directories along with a deeper detailed explanation with examples.
If you run the ls -l
command on the root directory (/
) of a Linux box you will see something similar to the example below which was run on a version of Debian:
steve@tweaks:/# ls -l
total 68
lrwxrwxrwx 1 root root 7 Mar 22 2023 bin -> usr/bin
drwxr-xr-x 5 root root 4096 Dec 15 10:03 boot
drwxr-xr-x 17 root root 4300 Dec 15 10:05 dev
drwxr-xr-x 95 root root 12288 Dec 15 09:58 etc
drwxr-xr-x 2 root root 4096 Dec 9 2022 home
lrwxrwxrwx 1 root root 7 Mar 22 2023 lib -> usr/lib
lrwxrwxrwx 1 root root 9 Mar 22 2023 lib32 -> usr/lib32
lrwxrwxrwx 1 root root 9 Mar 22 2023 lib64 -> usr/lib64
lrwxrwxrwx 1 root root 10 Mar 22 2023 libx32 -> usr/libx32
drwx------ 2 root root 16384 May 29 2023 lost+found
drwxr-xr-x 2 root root 4096 Mar 22 2023 media
drwxr-xr-x 3 root root 4096 May 29 2023 mnt
drwxr-xr-x 2 root root 4096 Mar 22 2023 opt
dr-xr-xr-x 333 root root 0 Dec 15 10:05 proc
drwx------ 5 root root 4096 Dec 15 10:04 root
drwxr-xr-x 29 root root 1360 Jan 1 20:01 run
lrwxrwxrwx 1 root root 8 Mar 22 2023 sbin -> usr/sbin
drwxr-xr-x 2 root root 4096 Mar 22 2023 srv
dr-xr-xr-x 13 root root 0 Dec 15 10:05 sys
drwxrwxrwt 8 root root 4096 Jan 1 05:55 tmp
drwxr-xr-x 14 root root 4096 Mar 22 2023 usr
drwxr-xr-x 11 root root 4096 Mar 22 2023 var
If you are using a different Linux distribution than Debian or even a different version of Debian, your root file system may look slightly different. Notice some of the directories are symbolic links (pointers to another location) as indicated by the ->
representation.
Before we proceed further, it is important to understand the basics of applications on Linux because the different components of applications are organized in different directories, unlike Windows or Mac systems where all application files are typically just in one directory.
Applications on Linux are usually a combination of binaries, libraries, and configuration files. Binaries are executable files similar to an exe
file on Windows or an app
file on a Mac. Libraries are shared application components that are referenced by the binaries. Configuration files hold the application settings also referenced by the binaries. These three types of files will be stored in different directories as described in the "Cheat Sheet" below.
Root Directory Cheat Sheet
/
: File system "root" directory/bin
: User binaries files/boot
: Files used to boot your system/dev
: Special virtual file system for hardware devices/etc
: System configuration files/home
: User personal directories/lib
: System application libraries/lib32
: x86 32-bit application libraries/lib64
: x86 64-bit application libraries/libx32
: x32 32-bit application libraries (not very common)/lost+found
: Fragments of damaged files/media
: Removable devices such as USB devices/mnt
: Traditional mount point for fixed storage devices/opt
: Optional applications that you typically compile or copy over yourself/proc
: Special virtual file system that displays the running process/root
: The home directory of the root account/run
: System processes store temporary data/sbin
: System binaries used by the root account/srv
: Service data for server apps (ftp)/tmp
: Temporary application files/usr
: User-installed applications (typically from apt-get or equivalent package manager)/var
: Variable files that change frequently (log files)
Detailed Descriptions of Root Directories
BIN
The /bin
directory contains essential user binaries intended for all users on the system. In many Linux distributions, this folder is redirected via a symbolic link to /usr/bin
.
BOOT
The /boot
directory contains the important files required to boot or start up your system.
DEV
The /dev
directory is a special virtual directory for hardware devices that is generated at boot and updated by the kernel.
steve@tweaks:/dev# ls
autofs dma_heap loop1 null ptp2 tty0 tty23 tty38 tty52 ttyprintk ttyS22 ttyS9 vcsa2 vhost-vsock
block ecryptfs loop2 nvme0 pts tty1 tty24 tty39 tty53 ttyS0 ttyS23 udmabuf vcsa3 watchdog
btrfs-control fd loop3 nvme0n1 pve tty10 tty25 tty4 tty54 ttyS1 ttyS24 uhid vcsa4 watchdog0
bus full loop4 nvme0n1p1 random tty11 tty26 tty40 tty55 ttyS10 ttyS25 uinput vcsa5 zero
char fuse loop5 nvme0n1p2 rfkill tty12 tty27 tty41 tty56 ttyS11 ttyS26 urandom vcsa6 zfs
console hpet loop6 nvme0n1p3 rtc tty13 tty28 tty42 tty57 ttyS12 ttyS27 userfaultfd vcsu
core hugepages loop7 nvme1 rtc0 tty14 tty29 tty43 tty58 ttyS13 ttyS28 userio vcsu1
cpu_dma_latency hwrng loop-control nvme1n1 shm tty15 tty3 tty44 tty59 ttyS14 ttyS29 vcs vcsu2
cuse i2c-0 mapper nvme1n1p1 snapshot tty16 tty30 tty45 tty6 ttyS15 ttyS3 vcs1 vcsu3
disk initctl mcelog nvram snd tty17 tty31 tty46 tty60 ttyS16 ttyS30 vcs2 vcsu4
dm-0 input mei0 port stderr tty18 tty32 tty47 tty61 ttyS17 ttyS31 vcs3 vcsu5
dm-1 iommu mem ppp stdin tty19 tty33 tty48 tty62 ttyS18 ttyS4 vcs4 vcsu6
dm-2 kmsg mqueue psaux stdout tty2 tty34 tty49 tty63 ttyS19 ttyS5 vcs5 vfio
dm-3 kvm net ptmx tpm0 tty20 tty35 tty5 tty7 ttyS2 ttyS6 vcs6 vga_arbiter
dm-4 log ng0n1 ptp0 tpmrm0 tty21 tty36 tty50 tty8 ttyS20 ttyS7 vcsa vhci
dm-5 loop0 ng1n1 ptp1 tty tty22 tty37 tty51 tty9 ttyS21 ttyS8 vcsa1 vhost-net
ETC
The /ect
directory is where system configuration files are stored. Files such as those used for your cron
automated jobs, or the fstab
configuration file which tells the operating system which file systems to mount upon boot.
HOME
The /home
directory is where each user account has a personal directory. E.g. /home/steve
is my directory. This is similar to your desktop folder on Windows or MacOS. You can store random junk here just like your desktop.
LIB
The /lib
directory is where library files that applications install or depend upon are stored. On some distributions of Linux, this is typically a symbolic link to the /usr/lib
directory.
LIB32
/lib32
is similar to /lib
but offers a way for applications that are packaged to support multiple types of CPUs to install CPU architecture-specific compiled libraries. In this case, x86-32 (Intel/AMD 32-bit) libraries. On some distributions of Linux, this is typically a symbolic link to the /usr/lib32
directory.
LIB64
/lib64
is similar to /lib
but offers a way for applications that are packaged to support multiple types of CPUs to install CPU architecture-specific compiled libraries. In this case, x86-64 (Intel/AMD 64-bit) libraries. On some distributions of Linux, this is typically a symbolic link to the /usr/lib64
directory.
LIBX32
/libx32
is similar to /lib
but offers a way for applications that are packaged to support multiple types of CPUs to install CPU architecture-specific compiled libraries. In this case, x32 ABI (32-bit but offers some 64-bit instructions) libraries. This is not very common. On some distributions of Linux, this is typically a symbolic link to the /usr/libx32
directory.
LOST+FOUND
The /lost+found
directory is where fragments of damaged files are restored by the fsck
(file system consistency check) utility. If a file is being modified or deleted and at the same moment the computer loses power, the data could end up corrupted and the fsck
tool will try to recover the lost data.
MEDIA
The /media
directory is typically where removable drives such as USB disks are mounted (automatically on some distributions) E.g. /media/
sandisk01` is where a sandisk USB disk may be mounted for access.
MNT
The /mnt
directory is the classic mount point for additional storage devices that are internal to the computer. It may depend on your distribution if /mnt
or /media
is used.
OPT
The /opt
directory is where optional applications that you typically copy over or compile yourself are stored. You will sometimes find /opt/bin
and /opt/lib
sub-directories that help organize the files further. I personally use this directory the most for my personal apps.
PROC
/proc
is a special virtual file system that displays running process information generated and updated by the kernel.
ROOT
The /root
directory is the home or personal directory of the root administrator account. Typically you don't want to put stuff here as you should not be running full-time as root.
RUN
The /run
directory is where system processes store temporary data such as process IDs and other files used for locking purposes.
SBIN
The /sbin
directory is where you can find essential system maintenance binaries. Some believe the origin of this directory was an intention to include only statically linked binaries while others believe these binaries require superuser (root) access to run.
SRV
The /srv
directory holds service data for server apps such as FTP and www root (although Apache uses /var/www
for it's WWW root).
TMP
/tmp
is for temporary application files. Things you don't care if they suddenly disappear as this directory may be deleted upon boot or on some sort of schedule depending on your specific Linux distribution.
USR
The /usr
directory is where your user-installed applications are organized in bin
, sbin
, lib*
, etc. For example, when you install a package with apt-get
, chances are the files will end up here. As mentioned earlier /bin
, /sbin
, and the variations of /lib
often point here.
steve@tweaks:/usr# ls -l
total 100
drwxr-xr-x 2 root root 36864 Dec 15 09:55 bin
drwxr-xr-x 2 root root 4096 Dec 9 2022 games
drwxr-xr-x 44 root root 4096 Oct 29 13:30 include
drwxr-xr-x 70 root root 4096 Dec 15 06:03 lib
drwxr-xr-x 2 root root 4096 Mar 22 2023 lib32
drwxr-xr-x 2 root root 4096 Oct 29 13:09 lib64
drwxr-xr-x 9 root root 4096 Dec 15 06:03 libexec
drwxr-xr-x 2 root root 4096 Mar 22 2023 libx32
drwxr-xr-x 10 root root 4096 Mar 22 2023 local
drwxr-xr-x 2 root root 20480 Dec 15 09:58 sbin
drwxr-xr-x 133 root root 4096 Nov 22 20:56 share
drwxr-xr-x 5 root root 4096 Dec 15 10:03 src
VAR
The /var
directory contains files that may change frequently, as if they are variable, such as log files in the world-famous/var/log
directory and the file I end up looking at the most: /var/log/messages
.
Reference
If you would like more details on the intention of a specific directory, check out the official Filesystem Hierarchy Standard.