I've just created a small DEB package, just to see how it works. My file structure was the following:

▶ tree          
│   ├── control
│   └── postinst
└── usr
    └── bin
        ├── myapp
        ├── myapp.deps.json
        ├── myapp.dll
        ├── myapp.pdb
        └── myapp.runtimeconfig.json

Basically, I created a Hello-World dotnet app. My control file is just:

Package: myapp
Version: 1.0
Maintainer: marcin
Architecture: all
Description: demo

and my postinst is:

echo "echo (from postinst)"

I created DEB with dpkg-deb --build myapp_1.0, and then installed it with sudo dpkg -i myapp_1.0.deb

I see that /usr/bin contains all my app's files as expected, and the app works when invoked with myapp.

Then, I decided to remove it with sudo apt remove myapp. It removed all of the app's files from /usr/bin. My question is: how did it know which files belong to it? I thought it would remove just the binary /usr/bin/myapp, but it also got rid of the myapp.dll, and all the rest.

Is it always the case that apt remove something will remove the program completely (and apt purge something will also remove all configs)? How does it know where to look? Will it also remove files that my app would create during runtime?

  • 1
    Please don't post screenshots of text. Copy the text here and use code formatting instead.
    – muru
    Oct 24, 2020 at 11:38
  • @muru Right, I fixed that. I miss the syntax-coloring though :)
    – mnj
    Oct 24, 2020 at 11:50

2 Answers 2


"How does it know which files to remove?" is exactly the same question as "How does it know which files to install?" You gave apt/dpkg that information in the package structure.

Files created at runtime must be removed by a prerm script in order to meet the Debian standard of idempotence: apt install foo followed by apt remove foo must return your system to state before the install.

Two exceptions:

  1. Files in /etc are removed by "purge", not by "remove".
  2. Files in /home are never removed by apt/dpkg. Those belong to the users.

Apt/dpkg does not have any setting to remove only a binary and leave other (non- /etc) files in place. If other packages depend upon a library, then package that library separately.

  • Thanks. One question. When I install a .deb file it obviously knows where to put the files, because this information is in the .deb itself. However, after installation, I may delete the .deb file. Where does apt store information about which files belong to which program (so that it can remove them later when runningapt remove)?
    – mnj
    Oct 24, 2020 at 11:49
  • It stores it in /var/lib/dpkg/info.
    – bamm
    Oct 27, 2020 at 2:01

Once you install your deb file, do this:

dpkg -L <packagename>

You will see that it lists all the content of your package. This means that the system knows which files were installed by a package and therefore knows what to remove.

This information is found in the following location:


For each package there exists a file named packagename.list containing exactly the same information as the output of dpkg -L earlier.

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.