Linux – The different uses of folders in the / (root) directory

directory-structurelinuxroot-filesystem

There are a lot of folders in the / directory what do they all do?
I know a few like /dev has links to devices in the system but what about /lost+found or /proc I just am curious.

Best Answer

The official reference for this on Linux is the Filesystem Hierarchy Standard. Distributions mostly follow the FHS (currently at version 3.0), but can occasionally deviate. Other Unix variants have many similarities but again can deviate. There is also a good summary on Wikipedia.

I'll summarize the role of each directory that is found on typical Linux installations. See the FHS or Wikipedia for more details about the role of each directory.

  • /bin: system programs meant for every user. See also /usr/bin.
  • /boot: files used to start up the system: typically a bootloader, a kernel image, and a few associated files. These files are mostly not accessed after booting.
  • /dev: device files. These are the ways applications communicate with hardware and more generally with kernel features that are about shuffling data around, such as disk partitions, terminals including virtual ones, etc.
  • /etc: system configuration files. (So named because it started out as “stuff that didn't fit in the other directories”, but nowadays it's exclusively for configuration files on Linux and mostly if not exclusively for configuration files on other Unix variants. Miscellaneous stuff is now under /var.)
  • /home: the directory containing users' home directories. E.g. Alice's files are typically under /home/alice. On systems with many users, the administrator may choose to have more levels (e.g. /home/faculty/alice, /home/students/bob, …). A few sites have home directories at a different location such as /homes, /users, …
  • /lib contains shared libraries. See also /usr/lib.
    Some distributions have other directories such as /lib32 and /lib64 to store libraries for different processor architectures.
  • /lost+found: for files recovered from filesystem corruption (but you're rarely so lucky).
  • /media: contains mount points for removable media. On some systems, the mount points are at a third level, under directories named after users.
  • /mnt: There used to be a dispute as to whether /mnt should be a directory that's available to the system administrator as a temporary mount point, or whether it should be a directory where the administrator can create subdirectories to be used as mount points. Nowadays the first position has won, and /media plays the second role.
  • /opt: contains additional software with one subdirectory per software package. Some distributions use it heavily, others not at all.
  • /proc: contains one subdirectory per process, exposing various information about the processes. That's where tools such as ps and top get their information. Not present on all Unix variants (BSD tends not to have it). On Linux, /proc also contains information about the system in general, but see also /sys. Content in /proc is generated on the fly by the kernel when an application reads it.
  • /root: the root user's home directory. Not present on all systems; traditionally root's home directory was /.
  • /run: an in-memory filesystem containing system files that don't need to be preserved upon reboots, such as information about running services. There are typically per-user directories under /run/user. This is a Linux thing.
  • /sbin: system programs meant only for administrators. See also /usr/sbin.
  • /srv: sort of like /home, but for system services. A creation of the FHS that hasn't been universally adopted.
  • /sys: like /proc, but presents information about kernel drivers and about hardware (the use of /proc for non-process-related information is deprecated but files that were in /proc remain in /proc for backward compatibility). Specific to Linux.
  • /tmp: temporary files, accessible by every user. This is often an in-memory filesystem.
  • /usr: This is where most of the software is installed. /usr contains subdirectories such as /bin, /lib and /sbin (but usually not /etc). The distinction is that the subdirectories of / contain essential files needed while the system is starting, and /usr contains all the rest. /usr exists separately because there were reasons to keep it on a separate filesystem (which could be read-only, and shared between multiple machines) but the distinction is not always relevant, and less and less so as time goes on, so e.g. /bin can be a symbolic link to /usr/bin or vice versa. The name comes from “user” but it has been a very long time since /usr had anything to do with users, today /usr contains system files and that's that.
  • /var: contains files that tend to change over time, in contrast with /usr which contains files that don't change except when upgrading or installing software. Unlike /tmp, the files under /var are (for the most part) meant to be preserved if the system reboots. /var is pretty diverse: it contains caches, metadata about installed software, printer spools, system mail, log files, temporary files (like /tmp, but /var/tmp is always preserved upon reboot and usually has more space), etc.
Related Question