I'm trying to make an interactive docker container based on a 3rd party docker image where /usr/share/man has been deleted to save layer space. Every file that belongs in that folder is part of an apt package that otherwise works fine. I would like to restore just those deleted manpages for the packages I currently have installed.

The way to solve this problem for an individual package is to reinstall it. I could potentially --reinstall every package on the container with something like,

apt-get --reinstall install \
    $(dpkg --get-selections | awk '$2=="install"{print $1}')

but is there a way to selectively make dpkg recreate a deleted folder without having to resort to such a time- and bandwidth-consuming process every time I rebuild?


You will need to reinstall the affected packages because the local image won't have any content to let to repair.

However you can potentially minimise the amount of repair needed.

You can determine which packages have files in /usr/share/man with a loop such as

for pkg in $(dpkg --get-selections | awk '$2=="install" { print $1}')
  f=$(dpkg -L $pkg | grep /usr/share/man)
  if [ -n "$f" ]
    echo $pkg has files in /usr/share/man

You can then reinstall those packages.

We can potentially even limit further to those that are missing by looking at /var/lib/dpkg/info/$pkg.info for the man files and compare to what is missing and only reinstall those.

However, at the end of the day, I think you're going to reinstall a lot of packages. On my Jessie install, 703 packages had files in /usr/share/man. That's better than the 2200 packages installed, but still a lot. A local mirror to avoid network traffic seems indicated.

| improve this answer | |
  • The variant I ended up using was apt-get install --reinstall $(dpkg --search /usr/share/man | sed 's,: /usr/share/man$,,' | tr , ' '), which in my docker container reinstalls 271 things, which I can live with. – Dan Aug 19 '16 at 5:26

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.