Score:2

How to get a complete file list for all packages?

mw flag

I tried using apt-file list --regexp ".*", but it's not working, probably because the returned content is too extensive.

francois P avatar
in flag
` apt list --installed > filename` didn't fit your needs ?
jp flag
I'm just curious what would be the use case or the problem you are trying to solve with this?
OffIGoThen avatar
mw flag
This is the task assigned to me by my mentor, and I'm not sure of the exact purpose behind it.
jp flag
Is this a homework or an actual task required in a business environment?
OffIGoThen avatar
mw flag
I believe it is an acuactual task as my mentor seems to be in need of me to solve it..
nightWolf avatar
nr flag
What is exact requirement here: - Do you need list of all the packages installed on the server OR - Do you need list of all the files installed with packages installed on the server. ?
OffIGoThen avatar
mw flag
I want to download file list of all packages in the apt database to my local system. However, the results are too extensive, and I can't achieve it with a simple command.
OffIGoThen avatar
mw flag
I need all the files installed with packages in apt database.
OffIGoThen avatar
mw flag
But the packages may not be installed or downloaded locally because I need all the packages.
cc flag
wouldn't : apt-file search / # be faster ? (ie, apt-file search pattern) : no regex required, and all files have at least one "/" in it, and should match?
cc flag
and depending on the task your mentor intends to do ... _"To list all local files not belonging to any installed package, you might want to take a look at the cruft or the cruft-ng package."_ ( https://debian-handbook.info/browse/stable/sect.apt-file.html )
OffIGoThen avatar
mw flag
"apt-file search /" is indeed faster. However, I encountered the same issue as using regexp. The command eventually terminates with: "terminated by signal 13". I suspect it might be because there are too many results returned. I don't need cruft for now, but I will explore its usage further. Thank you very much for your response.
Score:3
nr flag

You can pull file list for all the packages using command apt-file list --regexp ".*" however this will take time in gathering the list of all files. The same is mentioned on the man page of the command apt-file:

       -x, --regexp
       Treat pattern as a (perl) regular expression. See perlreref(1) for
       details. Without this option, pattern is treated as a literal
       string to search for.

       Be advised that this option can be rather slow.  If performance is
       an issue, consider giving apt-file non-regex pattern matching too
       much and pipe the output to perl -ne '/<pattern-here>/'.  This
       enables apt-file to use more optimizations and leaves less work to
       the "slower" regex.

Another way to pull file list for all the installed packages is by using below command:

for package in $(apt list --installed| awk -F"/" '{print $1}'); do
  dpkg --listfiles "$package";
done

You can adjust the output as per your requirement.

In case you want to pull file list for all the packages from apt db, you should go with apt-file which will take time as there are usually thousands of packages(depending on repos configured) in apt db, so there will be millions of files to list. You can go with either command:

apt list | awk -F"/" '{print $1}' > package_list
apt-file list -f package_list

or

apt-file list --regexp ".*"
OffIGoThen avatar
mw flag
Thank you for your response, but what should I do if the package is not installed locally?
nightWolf avatar
nr flag
Just updated the answer as per your requirement. Hope this is helpful .
OffIGoThen avatar
mw flag
I tried this command, and it's indeed very slow. I guess it might take a day to complete the execution. I'm not sure if there's a faster method, but your response has already met my basic needs. Thank you once again.
Score:2
jp flag

Another option of listing all files in all packages in the APT cache, as the suggestions from @nightWolf utilizes apt, which is not good in scripts...

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

#!/bin/bash

for package in $( \
  apt-cache dump \
    | grep -e "^Package" \
    | awk '{print $2}' \
    | sort )
do
  apt-file list "$package";
done

Again, the task is slow however you try to do it. The APT cache database exists and has the tools for performing all the relevant searches. Dumping this information out as text does not seem useful.

OffIGoThen avatar
mw flag
Thank you for your addition. I'm wondering if there's a way to achieve this requirement without using the 'apt-file list' command, as using 'apt-file list' repeatedly has consumed too much time.
OffIGoThen avatar
mw flag
The root cause of the problem might be unreasonable requirement , I guess. (Sigh)
jp flag
Tell your mentor the Internet says they are requesting stupid things. :)
OffIGoThen avatar
mw flag
lol,you are right.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.