gitmyhub

lsbtw

C ★ 42 updated 15d ago

rewriting UUTILS::LS in C

A from-scratch C reimplementation of the `ls` command built as a learning project, showing step by step how directory listing, file metadata, and permission strings actually work at the system call level.

CPOSIX syscallsstat()opendir/readdirsetup: easycomplexity 2/5

lsbtw is a from-scratch reimplementation of the ls command written in C, built as a learning project to accompany a video tutorial. The goal is not to produce a replacement for the standard ls tool but to show, step by step, how ls actually works under the hood.

The ls command is something every Linux and macOS user runs constantly, but few people look at what it does internally. This project walks through opening a directory, reading its entries, and then making a single stat system call per entry to retrieve all the information that appears in a long listing: the file type, the permission string, the number of hard links, the owner and group names, the file size in bytes, and the last modification timestamp. Each of those fields maps directly to a piece of data returned by the kernel, and the code shows exactly how to read and format them.

The implemented flags match the most common ls options: running it without arguments lists the current directory, -a includes hidden files (those whose names start with a dot), -l prints the long format with all the file metadata, and flags can be combined and pointed at a specific path.

The README is honest about what is still missing. Entries come out in the order the filesystem hands them back rather than sorted alphabetically, and the columns in long format are not padded to line up neatly. The author flags both as exercises for viewers who followed the video, with a hint that qsort handles the sorting case.

This is an educational codebase aimed at developers who want to understand how core Unix utilities interact with the filesystem, not a production tool.

Where it fits