Tuesday, February 25, 2020

extracting filenames from packages available in debian

Back in 2016, I wanted to check the names of existing command-line utilities in order to avoid a collision when I renamed my blogging software to wrt.

I wound up using apt-file data to see what binaries are available from Debian packages, and I’ve referenced the list of files I generated then a bunch of times since. It’s obviously way out of date by now, and today I had a similar question to answer, so here’s a scripted version of that process that worked on my current machine, running Debian Buster:

#!/bin/sh

# Make sure we've got apt-file and lz4 compression utils:
sudo apt install apt-file lz4

# Update lists:
sudo apt-file update

cd /var/lib/apt/lists
lz4cat ./*.lz4 | \
  grep -E '^(usr/bin/|sbin/|bin/)' | \
  cut -f1 -d' ' | \
  perl -pe 's/^(.*)\/(.*)$/$2/' | \
  sort | uniq > ~/used_names.txt

Then you can grep whatever ~/used_names.txt to look for binaries.

The main difference here is that the contents lists are now in /var/lib/apt/lists, as LZ4-compressed files named like deb.debian.org_debian_dists_buster_main_Contents-amd64.lz4.

I haven’t taken the time to investigate whether this data is still just loaded for apt-file’s benefit or is in some way more integrated with apt or what. Maybe I’ll revisit at some point.

Today’s used_names.txt is attached to this post just in case it’s helpful to people coming in from web search.

more: used_names.txt

p1k3 / 2020 / 2 / 25
tags: topics/apt, topics/debian, topics/shell, topics/technical