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

2 Answers 2


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, 2015 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, 2017 at 13:20
  • 1
    /tmp/dummy seems more convenient that ~/dummy and the need to remove it. Jul 1, 2017 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. Jan 31, 2019 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, 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.


  • 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. Jan 21, 2014 at 17:00
  • 2
    Yes, 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.
    – Ruslan
    May 18, 2020 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.