What does dpkg --configure -a do?

The title explains it, but why should have to use it when I am installing a package via Terminal on my box then the installation fails, why is this and what does "dpkg --configure -a" do to fix it that the ordinary "sudo apt" cannot do?


apt, aptitude, synaptic etc. are frontends to the same tool: dpkg. dpkg is very low-level, and apt isn't particularly smart. So if package configuration was interrupted, apt tells you to descend to the lower level to fix it. Note that apt may not be aware of the packages which caused the problem (they may be manually installed local packages, and they may be a hundred packages and not one) and keeping it simple, it tells you to use the tool that is aware of them. Mitch has already posted what this command does.


From the manpage:

--configure package...|-a|--pending
          Reconfigure an unpacked package. If -a  or  --pending  is  given
          instead  of  package, all unpacked but unconfigured packages are
          configured.

          Configuring consists of the following steps:

          1. Unpack the conffiles, and at the same time back  up  the  old
          conffiles, so that they can be restored if something goes wrong.

          2. Run postinst script, if provided by the package.