A file system is an organization of data and metadata on a storage device. A filesystem contains the methods and data structures that an operating system uses to keep track of files on a disk or partition.
Linux follows single hierarchal directory structure. Everything starts from the root directory, represented by '/', and then expands into sub-directories. Where DOS/Windows had various partitions and then directories under those partitions, Linux places all the partitions under the root directory by 'mounting' them under specific directories.
On a standard Linux system, the layout generally follows the scheme presented below. The layout represented below is considered from a RedHat system, but depending on the operating system varient it may vary slightly.
/ --- |_ bin
|_ boot
|_ dev
|_ etc
|_ home
|_ lib
|_ lost+found
|_ media
|_ mnt
|_ net
|_ opt
|_ proc
|_ root
|_ sbin
|_ srv
|_ tmp
|_ usr
|_ var
The tree of the file system starts at a forward slash (/). This directory, containing all underlying directories and files, is also called the root directory or the root of the file system.
1. / root directory
- Every directory under the root directory is on the root partition, unless it has a separate entry in the full listing from df
- Every single file and directory starts from the root directory.
- Only root user has write privilege under this directory.
- /root is root user’s home directory, which is not same as /.
2. /bin Essential command binaries
- Contains common binaries/commands, shared by the system, the system administrator and the other users.
- Essential commands used in single-user modes are located under this directory.
- Example: ls, vi, cp, ping, grep, pwd, mkdir, rm, chmod, date, cat etc
3. /boot Static files of the boot loader
- Contains boot loader files
- The startup files and the Kernel initrd, vmlinuz and grub data
4. /dev Device files
- Contains references to all the CPU peripheral hardware, which are represented as files with special properties.
- These include terminal devices, usb, or any device attached to the system.
- Example: /dev/console, /dev/tty, /dev/ttyS0 etc
5. /etc System configuration files
- Contains Host-specific system configuration
- Contains configuration files required by all programs.
- Startup and shutdown scripts to start/stop host specific individual programs.
- Example: /etc/grub.conf, /etc/resolv.conf, /etc/host.conf etc
6. /home User home directories
- Contains home directories of the common users.
- Contains user specific config/settings and saved files
- Users can store their personal files
- Example: /home/john. /home/user10 etc
7. /lib System libraries
- Essential shared libraries and kernel modules
- Supporting library files, includes files for programs (located under /bin and /sbin) required by the system and the users.
- Example: /lib/libpthread-2.5.so, /lib/libgcc_s.so.1, /lib/libresolv.so.2 etc
8. /lost+found Recovery files
- Files that were saved during failures are here.
- Each partition has its own lost+found directory.
- This is the place where corrupted files are placed when they are found during a filesystem check.
9. /media Removable media devices
- Mount points for removable media such as CD-ROMs
- Examples: /media/cdrom, /media/floppy
10. /mnt Mount directory
- Temporary mount directory where filesystems can be mounted
11. /net Mount directoty for remote file systems
- Standard mount point for entire remote file systems
12. /opt Optional application software packages
- Typically contains add-on and third party software.
13. /proc Process information
- Contains information about system processes and resources as a virtual file system
- Virtual filesystem documenting kernel and process status as text files, e.g., uptime, network. In Linux, corresponds to a Procfs mount
- Example: /proc/uptime, /proc/cpuinfo etc. Also /proc/{pid} - contains information about the process running with that particular pid
14. /root Home directory for the root user
- Mind the difference between /, the root directory and /root, the home directory of the root user.
15. /sbin Essential system binaries
- Programs for use by the system and the system administrator.
- Example: init, mount, iptables, reboot, fdisk etc
16. /srv Service data
- Data for services provided by this system
- Example: /srv/cvs contains CVS related data
17. /tmp Temporary files
- Contains temporary files created by system and users.
- Files under this directory are deleted when system is rebooted.
18. /usr Secondary hierarchy for read-only user data
- Contains the majority of (multi-)user utilities and applications
- Programs, libraries, documentation etc. for all user-related programs.
- /usr/bin contains binary files for user programs.
- /usr/sbin contains binary files for system administrators.
- /usr/lib contains libraries for /usr/bin and /usr/sbin
- /usr/local contains users programs that were installed from source
19. /var Variable data
- Storage for all variable files and temporary files created by users
- Content of the files that are expected to grow can be found under this directory
- This includes — system/app log files (/var/log), packages and database files (/var/lib), mail queue (/var/mail), print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp)