In this not at all regular series we introduce an awesome and useful new command. Mostly so that I can find it again if I need to.
Today, I present: dpkg-divert
So, for example, if I want to have my own customised /etc/bash.bashrc which I don’t want to be overwritten when bash is upgraded by the packaging system, I might do something like:
$ sudo dpkg-divert --add --rename --divert /etc/bash.bashrc.divert /etc/bash.bashrc
This will rename /etc/bash.bashrc to /etc/bash.bashrc.divert (–rename), so I can put my own custom /etc/bash.bashrc there, and any future dpkg operation which would normally touch /etc/bash.bashrc will now instead happen to /etc/bash.bashrc.divert.
Super useful! Here’s an example of real-world usage – you can greatly improve your Linux audio experience with:
$ sudo dpkg-divert --add --rename --divert /usr/bin/pulseaudio.real /usr/bin/pulseaudio
$ sudo ln -s /bin/false /usr/bin/pulseaudio
Now for anything that actually does require pulseaudio (generally only shit software), you can do pulseaudio.real
to start it and pulseaudio.real -k
once you’re done.
I wish I’d known about dpkg-divert
10 years ago!