Linux Directories and Links: Complete System Programming Guide

 

Linux Directories and Links: Complete System Programming Guide

Linux Directories and Links: Complete System Programming Guide

📄
8 Topics
💻
40+ Code Examples
🎯
50+ Interview Qs
🆓
Free

About This Chapter

Chapter 18 of “The Linux Programming Interface” covers the internals of Linux directories, hard links, symbolic links, and the system calls for managing them. This guide breaks it down into 8 focused topics with simple language, inline diagrams, real code examples, and interview questions — perfect for students and embedded engineers.

Topics Covered

InodesHard Links Symbolic Linkslink() unlink()rename() mkdir()rmdir() opendir()readdir() nftw()getcwd() chdir()openat() realpath()dirname() basename()chroot()

All Topics

Part 1: Inodes and Hard Links START HERE

What is an inode, what it stores, how directories map names to inodes, hard link creation and deletion, link count.

inode structurest_nlink link countstat()
Part 2: Symbolic (Soft) Links

What symlinks are, how they differ from hard links, dangling links, symlink chains, which syscalls follow them.

ln -sstat vs lstat dangling linkELOOP
Part 3: link() and unlink()

Creating hard links with link(), removing them with unlink(), when files are truly deleted, the anonymous temp file trick.

link()unlink() temp file tricklinkat()
Part 4: rename() · mkdir() · rmdir() · remove()

Renaming and moving files, creating directories, removing directories, atomic file updates with rename().

rename()mkdir() rmdir()remove() mkdirp trick
Part 5: Reading Directories

opendir(), readdir(), closedir(), rewinddir(), struct dirent, d_type, fdopendir(), readdir_r().

DIR streamstruct dirent d_typereaddir_r
Part 6: nftw() — File Tree Walking

Recursively walking a directory tree, preorder vs postorder, flags, recursive deletion, find-like searches.

nftw()FTW_DEPTH FTW_PHYSrm -rf impl
Part 7: Working Directory and openat()

getcwd(), chdir(), fchdir() for save/restore, openat() for thread-safe file ops, chroot() jails.

getcwd()chdir() fchdir()openat() chroot()
Part 8: symlink() · readlink() · realpath() · dirname() · basename()

Creating symlinks, reading symlink contents, resolving canonical paths, splitting pathnames into parts.

symlink()readlink() realpath()dirname() basename()

Start Learning

Begin with Part 1 and work through each topic in order.

Start: Inodes and Hard Links → EmbeddedPathashala Home

Leave a Reply

Your email address will not be published. Required fields are marked *