Understanding Unix/Linux Files, File Types, Partitions and Filesystem Hierarchy
This article explains the Unix principle that everything is a file, describes regular and special file types, outlines why and how disks are partitioned, introduces mount points, and details the standard Linux filesystem hierarchy and inode metadata.
Unix and Linux follow the principle "everything is a file"; processes, devices, directories and even sockets are represented as files, which simplifies system design despite the existence of special file types such as pipes and sockets.
File types are categorized as regular files, directories, special device files, symbolic links, sockets and named pipes. The first character of ls -l output indicates the type (e.g., - for regular files, d for directories, l for links, c for character devices, s for sockets, p for named pipes, b for block devices). The following table summarizes the symbols:
Symbol
Meaning
-
Regular file
d
Directory
l
Link
c
Special file (character device)
s
Socket
p
Named pipe
b
Block device
Partitions divide a disk into independent sections to improve data safety and system robustness. Separate partitions isolate system files, user data and swap space, so a failure in one partition does not corrupt the whole system. Journaled file systems (e.g., ext3) maintain a log to recover from crashes.
Linux typically uses two main partition types: data partitions (type 83 ) and swap partitions (type 82 ). Additional partitions may host other file systems such as FAT, ReiserFS, JFS, NFS, etc. Common layout includes a root partition (/, 100‑500 MB), one or more data partitions, and one or more swap partitions, often sized at twice the RAM.
Mount points attach partitions to the directory tree. An empty directory (e.g., /opt/media ) is created, then the mount command links the partition to that directory. The /etc/fstab file defines automatic mounts at boot, while the df -h command shows currently mounted filesystems and their usage:
freddy:~> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda8 496M 183M 288M 39% /
/dev/hda1 124M 8.4M 109M 8% /boot
/dev/hda5 19G 15G 2.7G 85% /opt
/dev/hda6 7.0G 5.4G 1.2G 81% /usr
/dev/hda7 3.7G 2.7G 867M 77% /var
fs1:/home 8.9G 3.7G 4.7G 44% /.automount/fs1/root/homeThe Linux filesystem is presented as a hierarchical tree rooted at / . Standard top‑level directories include:
Directory
Purpose
/bin
Essential user commands
/boot
Boot loader and kernel files
/dev
Device files representing hardware
/etc
System configuration files
/home
Home directories for regular users
/initrd
Initial RAM disk image
/lib
Shared libraries
/lost+found
Recovered files after crashes
/mnt
Mount points for temporary mounts
/opt
Optional third‑party software
/proc
Virtual filesystem exposing kernel info
/root
Home directory of the root user
/sbin
System administration binaries
/tmp
Temporary files cleared on reboot
/usr
Secondary hierarchy for user programs and data
/var
Variable data such as logs, mail, spool
Each file is represented by an inode that stores metadata: owner, group, type, permissions, timestamps, link count, size and the disk addresses of the data blocks. The filename and directory entries are stored separately, linking names to inode numbers; the command ls -i displays inode numbers.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.