Explanation of the Unix File System Hierarchy
The structure of a Unix or Linux file system can be quite confusing to newbies. This post touches on the main directories found on a typical Unix or Linux system.
For more in depth information, I recommend the file-hierarchy man page from Arch Linux: https://jlk.fjfi.cvut.cz/arch/manpages/man/file-hierarchy.7.
/ - root
- The root of the entire file system hierarchy
- Not to be confused with /root, the home directory for the root user
/bin - binaries
- Command binaries available in single-user mode, or for all users
- Examples: cat, ls, cp, ping
/boot - boot loader
- Contains boot loader files
- Examples: kernels, initrd
/dev - device files
- A device file allows for device drivers to be treated like ordinary files (“everything in Unix is a file”)
- The two general types of device files are character special files and block special files
- Examples: /dev/null, /dev/random, /dev/full, /dev/tty
/etc - config files
- Contains static config files used by the system
- Linux restricts binaries from being placed in /etc
- Examples: /etc/shadow, /etc/passwd, /etc/crontab, /etc/magic
/home - user’s home directories
- Home directories for non-root users
- Contains saved files and personal settings
/lib - libraries
- Contains essential shared libraries needed by programs in /bin and /sbin
/media - removable media
- The default mount point for removable devices, such as USBs and CDs
/mnt - mounted devices
- Commonly used by system admins as a temporary file system mounting point
/opt - optional programs
- Optional application software and packages
- Good location for user installed programs
/proc - process information
- A virtual file system for displaying process and kernel information as files
- The files are generated automatically on the fly when they are called
- Examples: /proc/cpuinfo, /proc/stat, /proc/self
/root - root’s home directory
- Home directory for the root user
- Not readable or writeable by other users
/run - run-time variable data
- Information about the running system since last boot, for example, currently logged in users and running daemons
/sbin - system binaries
- Contains essential utilities for the system
- Examples: /sbin/init, /sbin/mkswap, /sbin/sfdisk
/srv - server data
- Data served by this system, such as web or FTP servers
/tmp - temporary files
- For temporary files that will be erased when the system reboots
/usr - user programs
- Holds executables, libraries, and shared resources that are not system critical
- Non-essential binaries are in /usr/bin and non-essential system binaries are in /usr/sbin
/var - variable files
- For files whose content is expected to change regularly
- Examples: /var/log, /var/spool, /var/mail