How can I do this without reinstalling the rest of the files as well?


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
  • 2
    It should also be noted that apt-get download downloads to the current working directory . – user369927 Jan 18 '15 at 16:14
  • 5
    You can avoid extracting the entire archive using a pipeline involving dpkg-deb --fsys-tarfile and tar, like so: dpkg-deb --fsys-tarfile "$package"*.deb | tar -x ./path/to/file – kojiro May 8 '17 at 13:20
  • 1
    /tmp/dummy seems more convenient that ~/dummy and the need to remove it. – Karl Richter Jul 1 '17 at 19:42
  • 1
    Prefer apt-get download since apt-get --download-only install will stop if the package is already installed. As indicated by camypaj's answer. – Julien Carsique Jan 31 '19 at 11:11
  • To expand on kojiro's comment, I had to look at what's the default value of nginx's worker_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-yuri Mar 30 '19 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.


  • 3
    if you have a package already installed then it's typically found in /var/cache/apt/archives/ and you shouldn't have to download it. – Ahmed Masud Jan 21 '14 at 17:00
  • 2
    Yes, but only if the package was installed relatively recently, and the archives have not been manually or automatically cleaned. – joeytwiddle Jan 29 '16 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. – Ruslan May 18 '20 at 16:59

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.