An ubuntu package contains a file that is not acceptable to me (not a config). I've applied my changes to it, but I'm afraid that eventually the package that it came from will be updated and my corrected version of the file will be overwritten. I set chattr -i, so I'm hoping that apt will at least fail with an error trying to overwrite it, but I would like to avoid errors altogether.

Is there a way to make apt just leave the file alone and never modify it? Or some other clean way to override it?

No, I don’t want to prevent the package from updating, I need to freeze only one file.


1 Answer 1


Use dpkg-divert to have the installation of the file write somewhere else instead:

dpkg-divert --divert /path/to/targetfile.diverted /path/to/targetfile
  • That's cool. I wonder if they have * support so all new configuration files for pulse-audio, vnstat, grub, etc. are written to a different directory and we can simply diff them later to roll-in the updates to our own configuration files? PS you could have changed your answer 21 minutes ago rather than deleting it and posting this new answer 6 minutes later. Oct 12, 2018 at 1:09
  • for me the --rename option was necessary: i.e: sudo dpkg-divert --divert /etc/slack.diverted --rename /etc/apt/sources.list.d/slack.list
    – dimisjim
    Aug 28, 2022 at 9:26

You must log in to answer this question.

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