Linux file system layout explained: home, etc, var and more
TUREFF• •0
Open a file manager on Linux and click on the top level of the drive, and you will see a set of short, cryptic folder names. There are no drive letters, no Program Files and no Users folder. The layout follows a long-standing convention called the Filesystem Hierarchy Standard, and once you know what each folder is for, the whole system makes more sense.
One tree, starting at root
Everything on a Linux system sits in one tree that starts at a single slash, called the root directory. Other drives and USB sticks do not get letters; they are attached, or mounted, at a folder somewhere in that tree. Paths use forward slashes, and names are case sensitive, so a file called Notes and one called notes are different files.
Where your own files live
- /home contains a folder for each user, such as /home/alex. This is your space: documents, downloads, pictures and your personal settings. The shortcut ~ in the terminal means your home folder.
- Hidden files and folders in your home begin with a dot. Many programs keep settings there, for example in a .config folder. File managers hide them by default; a keyboard shortcut, often Ctrl+H, shows them.
- /root is the home folder of the root administrator account, separate from /home.
If you back up only one folder, it is your home folder.
Programs and libraries
- /usr holds most installed software and its supporting files. Programs are usually in /usr/bin, libraries in /usr/lib and shared data such as icons and documentation in /usr/share.
- /usr/local is the conventional place for software you install yourself outside the package manager.
- /bin and /sbin traditionally held essential commands. On many modern distributions they are simply links into /usr.
- /opt is used by some third-party software that installs as a self-contained bundle.
Leave /usr to the package manager. Editing or deleting files there by hand is a good way to break updates.
Configuration
- /etc holds system-wide configuration files, mostly plain text. Examples include the list of file systems to mount at start-up, network settings and settings for services.
- Back up a file before editing it, for example by copying it with an extra .bak ending, and edit with administrator rights only when you understand the change.
- Your personal settings override many system defaults and live in your home folder instead.
Data that changes
- /var contains variable data that grows and changes while the system runs: logs in /var/log, package caches, mail spools, databases and websites on servers. If the disk fills up unexpectedly, /var is a common place to look.
- /tmp is for temporary files. Many distributions clear it at each restart, so never keep anything important there.
Hardware and the running system
- /dev contains device files representing hardware such as disks, for example /dev/sda or /dev/nvme0n1. Treat these with great care; writing to the wrong device can wipe a drive.
- /proc and /sys are virtual file systems created in memory by the kernel. They show information about running processes and hardware rather than files stored on disk.
- /run holds runtime information since the last boot.
Boot and mounting
- /boot contains the kernel and the files needed to start the system. On UEFI computers, the EFI System Partition is often mounted at /boot/efi.
- /mnt is a conventional place to mount a file system temporarily by hand.
- /media is where many desktops automatically mount USB sticks and external drives, often in a folder named after your user.
Libraries and other folders
- /lib traditionally held libraries needed by essential programs, and on many systems is now a link into /usr/lib.
- /srv is sometimes used for data served by the system, such as website files, though conventions vary.
- lost+found appears at the top of some file systems and holds file fragments recovered after a disk check.
Practical tips
- Work inside your home folder for everyday files.
- Use the package manager rather than copying files into system folders.
- Check disk usage by folder with the 'du' and 'df' commands or a graphical disk usage analyser when space runs low.
- Read the hier manual page, by typing 'man hier' in a terminal, for your system's own description of the layout.
Which Linux folder confused you most when you started? Share it in the comments.