How can I do this without reinstalling the rest of the files as well?
2 Answers
Download the package, for example transmission-daemon
, with
sudo apt-get --download-only install transmission-daemon
unpack the package with
mkdir ~/dummy
dpkg-deb -x /var/cache/apt/archives/transmission-daemon_*.deb ~/dummy
restore the file, for example /etc/init.d/transmission-daemon
sudo cp ~/dummy/etc/init.d/transmission-daemon /etc/init.d
remove the dir
rm -rf ~/dummy
-
2It should also be noted that
apt-get download
downloads to the current working directory.
– user369927Jan 18, 2015 at 16:14 -
5You can avoid extracting the entire archive using a pipeline involving
dpkg-deb --fsys-tarfile
andtar
, like so:dpkg-deb --fsys-tarfile "$package"*.deb | tar -x ./path/to/file
– kojiroMay 8, 2017 at 13:20 -
1
/tmp/dummy
seems more convenient that~/dummy
and the need to remove it. Jul 1, 2017 at 19:42 -
1Prefer
apt-get download
sinceapt-get --download-only install
will stop if the package is already installed. As indicated by camypaj's answer. Jan 31, 2019 at 11:11 -
To expand on kojiro's comment, I had to look at what's the default value of
nginx
'sworker_processes
setting on a range of machines. So I came up with the following command:for f in /var/cache/apt/archives/nginx-common*; do dpkg-deb --fsys-tarfile "$f" | tar xO ./etc/nginx/nginx.conf | grep worker_processes; done
.– x-yuriMar 30, 2019 at 15:21
I know this is a bit old, but here's my improvement:
$ sudo apt-get download <package-name>
instead of
$ sudo apt-get --download-only install <package-name>
I had a situation where the package was already installed (hence, the proposed solution didn't work), and I wanted to restore just one config file, in order to fix the problem.
Cheers
-
3if you have a package already installed then it's typically found in
/var/cache/apt/archives/
and you shouldn't have to download it. Jan 21, 2014 at 17:00 -
2Yes, but only if the package was installed relatively recently, and the archives have not been manually or automatically cleaned. Jan 29, 2016 at 4:33
-
The alternative would be to add
--reinstall
to the--download-only
mode. Then the package will be downloaded even if it had been already installed.– RuslanMay 18, 2020 at 16:59