explaingit

tonybanters/lsbtw

19CAudience · developerComplexity · 2/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((lsbtw))
    What it does
      Reimplements ls in C
      Reads directory entries
      Calls stat per file
      Formats metadata
    Implemented flags
      No args current dir
      -a hidden files
      -l long format
      Combined flags
    Known gaps
      No alphabetic sort
      No column padding
      Viewer exercises
    Audience
      Unix learners
      C beginners
      Tutorial followers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Learn how the `ls` command works internally by reading a minimal C implementation built for teaching.

USE CASE 2

Understand how Unix system calls like `stat()` return file metadata such as permissions, owner, size, and timestamps.

USE CASE 3

Use as a starting point to practise C skills by adding the missing features: alphabetical sorting with qsort and padded column output.

USE CASE 4

Follow along with a video tutorial that walks through building a real Unix utility from scratch.

Tech stack

CPOSIX syscallsstat()opendir/readdir

Getting it running

Difficulty · easy Time to first run · 5min

A standard C compiler (gcc or clang) is all you need. Clone the repo and run make or compile the C file directly. No external dependencies.

No license information mentioned, check the repository before using the code in your own projects.

In plain English

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.

Copy-paste prompts

Prompt 1
I'm studying the lsbtw source code, a C reimplementation of ls. Explain what the stat() system call returns and how each field maps to what you see in `ls -l` output.
Prompt 2
Using the lsbtw project as a reference, show me how to add alphabetical sorting to the directory entries using qsort() in C.
Prompt 3
Based on the lsbtw codebase, explain how to format the permission string (e.g. -rwxr-xr-x) from the st_mode field returned by stat().
Prompt 4
I want to extend lsbtw to pad columns so they line up like real ls output. Walk me through how to calculate the widest value in each column and use printf width specifiers.
Prompt 5
Explain how opendir() and readdir() work in C using the lsbtw project as context, and what the dirent struct contains.
Open on GitHub → Explain another repo

← tonybanters on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.