Unix File Systems
How a Unix system organizes files — the directory tree, file types, links, and the user/group permission model.
With a working Linux environment in place, this week is about the file system: how a Unix-like system organizes everything on disk, how you move around it from the shell, and how ownership and permissions control who can do what.
Everything is a file
Unix takes a famous stance: almost everything is a file — not just documents, but
directories, devices, and communication channels. ls -l shows the type in the first
character of each line:
| Symbol | Type | Example |
|---|---|---|
- | Regular file | a text file, a program |
d | Directory | /home, /etc |
l | Symbolic link | /bin -> /usr/bin |
c / b | Character / block device | /dev/tty, /dev/sda |
s | Socket | a local IPC endpoint |
p | FIFO (named pipe) | a mkfifo pipe |
The directory tree
Everything hangs off a single root, /. A Unix system follows a fairly standard layout, so
you can find your way around any distribution:
/
├── bin/ core user programs (ls, cp, sh, …)
├── sbin/ system/administrative programs
├── etc/ system-wide configuration files
├── home/ user home directories
├── lib/ essential shared libraries
├── usr/ the bulk of user programs & libraries
├── var/ variable data — logs, spools, databases
├── tmp/ temporary files (may be auto-cleaned)
├── mnt/ mount points for other filesystems
├── dev/ device files
└── proc/ virtual files: live process & kernel infoExact contents vary between distributions — this hierarchy is a convention (the Filesystem
Hierarchy Standard), not a hard rule. /proc and /dev are especially interesting: they
aren't real files on disk but views the kernel exposes as files.
Navigating
Paths are either absolute (from the root, e.g. /home/your-username/notes) or relative to
where you are now. Three shortcuts do most of the work:
~— your home directory.— the current directory..— the parent directory
Hard links and symbolic links
A filename is just a pointer to an inode — the on-disk record that actually describes a file. That indirection gives two kinds of links:
- A hard link is another name for the same inode. The data survives as long as any hard
link to it exists. Create one with
ln target name. - A symbolic (soft) link is a small file that just stores a path to another name. If the
target is removed, the link dangles. Create one with
ln -s target name.
ls -i shows inode numbers, so you can see two hard links share one inode while a symlink has
its own.
Users, groups, and permissions
Every file has an owner (a user) and a group. Permissions are granted separately to three classes — user (owner), group, and others — each with read (r), write (w), and execute (x) bits:
- rwx r-x r--
│ │ │ └── others: read
│ │ └──────── group: read + execute
│ └────────────── owner: read + write + execute
└─────────────────── type (- = regular file)The same bits are often written in octal, where r=4, w=2, x=1:
| Symbolic | Octal | Meaning |
|---|---|---|
rwxrwxrwx | 777 | everyone can do everything (rarely a good idea) |
rwxr-xr-x | 755 | owner full; others read + run — typical for programs |
rwx------ | 700 | private to the owner |
rw-r--r-- | 644 | owner writes; everyone reads — typical for files |
rw-rw-r-- | 664 | owner + group write; others read |
rw------- | 600 | private file, owner only |
Manage them from the shell:
chmod 644 fileorchmod u+x file— change permissionschown user:group file— change ownershipls -l— inspect type, permissions, owner, and group
Practice / lab
- Walk the tree: inspect the top-level folders under
/, then peek into/procand/dev. - Discover commands with
man,which, andtype; navigate withcd,pwd,ls -l. - Create hard and symbolic links with
ln/ln -sand compare inodes withls -i. - Change modes and ownership with
chmod/chown; experiment withumask. - Look at the account model in
/etc/passwdand/etc/group; tryid,who,groups.
References & resources
Required
- Filesystem Hierarchy Standard (FHS)
- Linux file types (TLDP)
- Linux file permissions explained (Red Hat)
- ECE 252 — The File System (video)
Optional / enrichment
- Linux Journey: The Filesystem
- An introduction to Linux permissions (DigitalOcean)
- Linux file system explained (video)
- Права доступа и владения файлами (RUS, video)
Self-check
- What is the difference between a hard link and a symbolic link?
- Which directory holds configuration files for most system services?
- What do the three groups in
rwxr-xr--represent, and what is it in octal? - How do you find the manual page for a command?
- Which virtual directory exposes information about running processes?
Introduction to Unix and Linux
What an operating system and a kernel are, where Unix and Linux came from, GNU, distributions, and the shell — the foundation for the course.
Compiling C/C++
How source code becomes an executable — the preprocess, compile, assemble, and link pipeline, libraries, memory layout, and make.