I have accidentally removed my apache2 startup file /etc/init.d/apache2 using rm /etc/init.d/apache2 command.

How can I get that back?

  • 6
    By restoring from your backup.
    – Amardeep
    Jul 2 '10 at 13:34
  • 2
    ed can be used (if you have a really good memory).
    – msw
    Jul 2 '10 at 13:37
  • 2
    Remount read-only. Right now. mount -oremount,ro /. Then continue looking for recovery programs, probably on a different machine because a read-only root is not appreciated by many programs.
    – Thomas
    Jul 2 '10 at 13:39
  • 2
    It's crazy how the Linux terminal doesn't have a garbage bin.
    – Hermann Ingjaldsson
    Jul 2 '10 at 14:16
  • 2
    @Hermann: if you are in a FreeDesktop (Gnome, KDE, XFCE) environment trash /etc/init.d/apache2 works as does restore-trash. I've never used them as source control and backups have always been sufficient and protect against more than a bad rm. ramendik.ru/docs/trashspec.html
    – msw
    Jul 2 '10 at 15:52

In this case the file is part of a package in the distribution. Just reinstall it.

In apt-based systems like Debian or Ubuntu, i believe it's just sudo apt-get --reinstall install apache2.2-common


Depending on your package manager, you can just reinstall the apache package. It will add that file back. Make sure you back up your configurations before you try though.


This won't help you after the event, but I highly recommend etckeeper. It maintains your /etc in a git/mercurial/darcs/bzr repository more or less automatically. It works best on Debian/Ubuntu where it's tied in with apt to make automatic commits before and after package installs, but it's usable on any Unix system. I'm using it on Mac OS X, for example. I can see the entire history of my /etc directory, and pull out previous versions of files when I need to.



Never tried it.


Depending on your filesystem you could try the following:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy