2026-05-06
Most "I just need a tiny database" problems get solved badly: a CSV that grows types it can't enforce, a SQLite file you can't diff in git, or a YAML blob you end up grepping with regex. GNU recutils sits in the gap. It's a 2009-era GNU project that defines a plain-text record format with types, keys, foreign keys, and constraints — plus a family of CLI tools to query and mutate it. Files are human-readable, vim-editable, git-diffable, and queryable with real expressions.
A .rec file looks like this:
%rec: Book
%type: Year int
%type: Rating range 1 5
%mandatory: Title
%key: Id
Id: 1
Title: The C Programming Language
Author: Kernighan, Ritchie
Year: 1978
Rating: 5
Id: 2
Title: The UNIX Programming Environment
Author: Kernighan, Pike
Year: 1984
Rating: 5
Now query it with proper expressions, not awk gymnastics:
# SELECT * WHERE Year > 1980
recsel -t Book -e "Year > 1980" books.rec
# SELECT Title, Author WHERE Author matches regex
recsel -t Book -p "Title,Author" -e "Author ~ 'Kernighan'" books.rec
# GROUP BY Author with count
recsel -t Book -G Author -p "Author,Count(Id)" books.rec
# Sort, limit, sum
recsel -t Book -S Year -n 3 books.rec
recsel -t Book -p "Sum(Rating)" books.rec
Mutations happen in place, and the tools refuse invalid writes:
recins -t Book -f Id -v 3 -f Title -v "K&R 2nd Ed" -f Year -v 1988 books.rec
recset -t Book -e "Id = 1" -f Rating -s 4 books.rec
recdel -t Book -e "Id = 2" books.rec
recfix --check books.rec # validate types, keys, mandatory fields
Multi-table with foreign keys works too. Add an Author record type, declare %rec: Book with %type: AuthorId rec Author, and recsel resolves the join:
recsel -t Book -j AuthorId -p "Title,AuthorId_Name" books.rec
Templating goes the other way with recfmt, and the toolkit ships rec2csv, csv2rec, plus an Emacs mode if that's your religion.
Why this beats the obvious alternatives:
git diff shows what changed, merges work, you don't need a binary tool to read it on a server. Schema lives next to the data, not in a separate migration.Install with apt install recutils or brew install recutils. The manual is one of the better GNU info documents — short, complete, full of examples. If you've ever started a side project with data.json and watched it metastasize, this is the tool you wish you'd reached for.
