Level 0 · Module 2

Files and directories

Understand how operating systems name and organize persistent information.

Difficulty
beginner
Time
9 min read
Prerequisites
Threads
Reading progress0% read

Not completed

By the end, you can

  • Distinguish files, directories, names, and paths.
  • Explain absolute and relative paths.
  • Trace basic create, read, update, and delete operations.

Summary

A file is a named collection of data. A directory organizes names into a hierarchy, and a path describes how to reach a file or directory.

Introduction

Programs need stable names for information that must survive after a process exits. The OS presents files and directories so programs do not need to manage raw storage locations.

Explanation

A directory can contain file names and names of other directories. An absolute path begins from a root location; a relative path begins from the current working directory. Separators and root notation differ across operating systems, but the hierarchical idea is shared. Common operations include create, open, read, write, rename, and delete.

Real-world example

Finding a project note

If the current directory is /home/lee/project, the relative path notes/todo.txt and the absolute path /home/lee/project/notes/todo.txt can identify the same file.

Follow the hierarchy

directory-tree.txttext
/home/lee/project/
├── app.js
└── notes/
  └── todo.txt

Code example

path-examples.txttext
current directory: /home/lee/project
relative path:     notes/todo.txt
absolute path:     /home/lee/project/notes/todo.txt
parent directory:  ..

Common mistakes

  • Assuming a file extension guarantees the file’s actual content.
  • Confusing a relative path with a path that starts at the root.
  • Believing deleting a directory name always securely erases every underlying byte immediately.

Quiz

Knowledge check

Your current directory is /work/site. Which path is relative?

Try it

Resolve the path

Starting in /school/cs/notes, resolve ../projects/demo.txt and explain what .. changes.

Key takeaways

  • Files hold named data; directories organize names hierarchically.
  • Absolute paths start at a root; relative paths start at a current location.
  • Paths provide logical names rather than exposing physical storage layout.
View module overview