Course contentsShow
← Computer Science
Lesson 1416 of 2,87232. File SystemsFree lesson

Directory Operations and System Calls

Learning common operations like create, delete, list, rename, and their corresponding system calls.

Directory Operations and System Calls

You'll learn the common directory operations and their corresponding system calls that let programs interact with file system directories.

What Are Directory Operations?

Just as you can create, rename, or delete files, you can perform similar operations on directories. These operations are fundamental to file system management and are exposed through system calls—special functions that request services from the operating system kernel.

Think of directory operations like managing folders on your desk: you can create a new folder, throw one away, list what's inside, or relabel it. The OS provides specific system calls to do these tasks programmatically.

Common Directory Operations

Create

Creates a new directory at a specified path. System call: mkdir() (make directory).

Delete

Removes an empty directory from the file system. System call: rmdir() (remove directory). The directory must be empty because deletion is permanent.

List

Reads the contents of a directory—all file and subdirectory names it contains. System calls: opendir(), readdir(), closedir() work together to iterate through entries.

Rename

Changes a directory's name or moves it to a different location. System call: rename() works for both files and directories.

Navigate

Changes the current working directory of the process. System call: chdir() (change directory).

Why System Calls Matter

These operations require kernel privileges because the file system's internal structures (like inodes and directory tables from previous lessons) must be updated safely. User programs can't directly manipulate these structures—they must ask the kernel through system calls.

Key Takeaway: Directory operations like create, delete, list, and rename are exposed through system calls (mkdir, rmdir, readdir, rename, chdir) that safely request kernel services to modify file system structures.