How do I find all the files either in source or in binary form in Debian package archive?

I tried the following but results were not helpful at all:

apt-file search *.c


apt-file search *.cc

So it either means that there are no c or cc files in the Debian archive (highly unlikely) or my search method was not good (more likely). The apt-file index is already updated.

  • 2
    As far as I know apt-file does not cover Debian source packages, only Debian binary packages. There is also codesearch.debian.net, but as far as I know, there is no equivalent service available locally. – Faheem Mitha Apr 28 '15 at 21:25
  • 2
    It's possible to run github.com/Debian/dcs locally (that's the code implementing codesearch.debian.net) but it takes a lot of resources! There's no index of source contents (unlike binary packages for which content indices are provided). – Stephen Kitt Apr 28 '15 at 22:00
  • @StephenKitt thank you. I found a solution but it's long-winded. Find all the packages which have been implemented in c using debtags search "implemented-in::c" send the output to another file or stdout. Take any of those packages, download them via apt-get source $PACKAGENAME and then extract from the original.tar.gz and then you know which files are in .c . Admittedly this is not scalable unless content indices for source packages are born sometime in this century. – shirish Apr 28 '15 at 22:54
  • umm... also nowadays extraction of the original tar.gz is a by-product of apt-get source itself . The extra step used to be necessary in the earlier versions so it's still stuck in my brain. – shirish Apr 29 '15 at 22:57

As you found out, apt-file only searches the filenames in binary packages. This is possible because Debian provides content indices for all the binary packages in its archives; for instance http://ftp.fr.debian.org/debian/dists/jessie/main/Contents-amd64.gz.

The easiest way to search the source code in Debian is to use http://sources.debian.net/ or directly https://codesearch.debian.net/ (the former is a front-end to the latter).

If you wish to search the source code locally, you'll need to download it; that requires a fair amount of bandwidth and storage. Debian 8 contains around 170GB of source code; compressed that takes around 40GB (10 DVDs). 40.3% of that is C code (that's probably a more accurate value than what you could determine with debtags); C++ code represents another 23.1% on top of that, so you're looking at nearly two thirds of the source code (by line count)... You can retrieve the source code package by package using apt-get source (as you point out yourself). You could also run your own instance of Codesearch using the source available on GitHub.

  • there doesn't seem to be a better way yet so awarding you the answer. I do wonder how you got the 40.3% of the distro is C code or the 22.3% . I was imagining more conservative numbers given that lot of other languages have been trying to make their mark on Debian. I did see the codesearch source at github but neither have the bandwidth or the patience to download that much data. While the existing setup leaves much to be desired, at least we got codesearch.debian.net. If memory serves right, this is also a pretty recent phenomena. – shirish Apr 29 '15 at 22:55
  • The service has only been available since July 2013, yes. The statistics come from the site, see the "170GB" link. I realise I mixed up Jessie (40.3% C) and Sid (22.3% C++ yesterday) figures; Jessie actually has 23.1% C++. – Stephen Kitt Apr 30 '15 at 4:43
  • thank you for your efforts, did share your name on my blog post flossexperiences.wordpress.com/2015/05/01/… – shirish May 1 '15 at 19:08

This probably is not the official Debian way of doing it, but this is how I would do it.

ar -p foo.deb tmp.tar.gz | tar tzv

Then of course you can pipe that output through grep.

ar -p foo.deb tmp.tar.gz | tar tzv | grep -i bar

By way of explanation: ar -p foo.deb tmp.tar.gz converts the .deb archive to a gzipped tar. Then we pipe the tar.gz file through tar and lists the files contained in the tarball (t lists, z unzips, and v does this verbosely)

There may be a simpler way, but when I recycle .deb archives for use on Slackware, that's basically the workflow I use.

  • could you explain a little about the command you are sharing. It looks like it's manipulating a single .deb package and trying to do something with it, not sure if it's pertinent to the question I raised. I am unfamiliar with the command you shared so a bit of info. on them will be helpful as well. – shirish Apr 28 '15 at 22:44
  • I have edited my answer with additional info. – Klaatu von Schlacker Apr 28 '15 at 22:56
  • 1
    did give you a rep point for trying out. This would not work in practise as I don't have the bandwidth to download the whole of debian archive. The only thing that could be done is go through /var/cache/apt/archives and do as you have shared but then again dunno if those 2000 odd packages totalling around 4 GB would be done in a proper way. As shared, good for effort though. – shirish Apr 28 '15 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.