File Concept & Directories
A file is more than bytes. It is a name, a set of attributes, a location, and a set of operations the OS promises to perform safely.
In plain English
A file is a labeled envelope. A directory is the filing cabinet that holds it.
By the end you will be able to
- List the attributes and operations of a file.
- Explain hierarchical directories and paths.
- Distinguish hard links from symbolic links.
- Know what metadata the file system stores.
File attributes and operations
A file has a name, size, owner, permissions, timestamps, type, and location. The operating system supports create, open, read, write, seek, close, delete, and truncate. The file system stores metadata separately from the data blocks. A file descriptor or handle is the process's reference to an open file.
Directories and paths
A directory maps names to file metadata. A hierarchical directory tree forms paths. An absolute path starts at the root; a relative path starts at the current directory. Directories themselves are files with special structure and permissions. Path resolution walks one component at a time, checking permissions and following links.
/home/ada/report.txt
^ ^ ^
root dir file
relative from /home/ada: report.txtHard links and symbolic links
A hard link is another directory entry for the same file metadata; deleting one name does not delete the data until the link count reaches zero. A symbolic link is a small file containing a path to another file; it can point across file systems and can become dangling. Links are a file-system feature, not a copy.
Key takeaways
- A file is data plus metadata plus a name.
- File descriptors are per-process handles for open files.
- Paths are resolved one directory component at a time.
- Hard links share metadata; symbolic links store a path.
- Permissions are checked during path resolution and I/O.
Common pitfalls
- Confusing a file name with the file itself.
- Assuming deleting a hard link deletes the data immediately.
- Forgetting that a symbolic link can dangle.
Kernel notes
- Name five file attributes.
- Trace absolute and relative path resolution.
- Compare hard and symbolic links.
Quick check
1. What is a hard link?
2. What happens when the last hard link to a file is removed?