1

I have thousands of Debian packages and I need to move all the executable files within those packages to one single directory. For a single package, I could use the ar command to extract package and then typical Debian package has a "data.tar.xz" file which actually contains the possible executables. I could then extract "data.tar.xz" using tar command and manually move the executables to new directory. It is a pain to do this for each package as there are thousands of packages and I was thinking to use a bash script to get the job done. My current directory structure looks like follows(only showed 3 packages here, all_executables is the directory to copy all the executables)

./git_2.28.0-1_armhf.deb
./libssm1-dbg_1.3-2.1_armhf.deb
./mariadb-client-core-10.0_10.0.28-2+b1_armhf.deb
 (the list goes on)
./all_executables

Once I extract a Debian package, every package usually have the same structure as follows-:

./control.tar.xz
./data.tar.xz
./debian-binary

Upon extracting data.tar.xz file there is few directories and these directories typically contains the executables. I need to copy these executables to one folder (all_executables). Could somebody help me to do this task. I am a beginner to bash and find being lost to get even started. Thank you for your time.

4
  • This question is cross-posted on SuperUser.
    – John1024
    Commented Aug 22, 2020 at 4:33
  • Sorry, I was confused which channel to use. I deleted it.
    – hEShaN
    Commented Aug 22, 2020 at 4:38
  • OK. Very good. As far as the question goes, you might want to clarify what you mean by 'executable' and how you expect this to work overall. For one, many .deb files contain 'executables' that won't run unless the associated libraries and other support files, also in the deb, are installed in the correct location in the directory structure.
    – John1024
    Commented Aug 22, 2020 at 5:00
  • I do not want to executables to run or to install packages. For one of the machine learning task, I need to have ARMv7 data in order to train a model.Therefore, I need to get ARM executables or shared objects(.so) files that lies within directories. For example, if you extract the git package in archive.raspbian.org/raspbian/pool/main/g/git/… , you would see there is git and git-shell executable file which is under the /usr/bin directory of the extracted package(similarly there are such executables in lib directory). I just need to copy all these to one place.
    – hEShaN
    Commented Aug 22, 2020 at 5:09

1 Answer 1

1

To begin, put this in a file called, say, script:

#!/bin/sh
for deb in "$@"
do
    ar x "$deb" ./data.tar.xz
    tar xvf data.tar.xz --transform='s|.*/||' --wildcards './usr/bin/*'
    rm ./data.tar.xz
done

To run it:

sh script /path/to/*.deb

The script will extract all contents of the /usr/bin/ directory of the tar file to your current directory.

You will want to tweak this:

  1. If you have old .deb files, the executables may be in data.tar.gz instead of data.tar.xz.

  2. From you comment, I gather there may be other files besides /usr/bin/* that interest you. They will have to be added to the command.

How it works

  1. #!/bin/sh indicates the start of a shell script.

  2. for deb in "$@"; do starts a loop over the arguments to the script.

  3. ar x "$deb" ./data.tar.xz extracts the data.tar.xz file.

  4. tar xvf data.tar.xz --transform='s|.*/||' --wildcards './usr/bin/*' extracts any file matching the glob ./usr/bin/* from data.tar.xz. x indicates extract. v (optional) indicates verbose. f data.tar.xz tells tar which file to extract from. So that every file is extracted into the current directory, -transform='s|.*/||' removes the directory names from the file to be extracted.

  5. rm ./data.tar.xz removes the data.tar file after we are done with it.

  6. done signals the end of the for loop.

2
  • Thank you for the detailed answer. The only concern is in the /usr/bin directory there could be other files as well. Basically, it won't always have ARM executable files or only few would be executables. Therefore, we should only copy the relevant files.
    – hEShaN
    Commented Aug 22, 2020 at 6:05
  • 1
    OK. Usually, files in /usr/bin are either executables or links to executables. If you believe that are other files and you want to exclude them, try tar's --exclude option.
    – John1024
    Commented Aug 22, 2020 at 6:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .