Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know this is something I shouldn't do, but it happened(Ubuntu 12.04.1 LTS) as a root user I deleted /usr/lib folder. Any ideas how to restore it?

share|improve this question
Take a look at This it might help. – Mitch Mar 26 '13 at 18:29
Some (or all) answers there might not help. Like the accepted answer, which says, "Since you've only deleted /usr/lib/* and not /lib/*, you can probably recover.") – Eliah Kagan Mar 26 '13 at 18:38

There are tools that might help you undelete the files, but usually it's a slow and mostly manual process. Search engines are your friends.

It may be easier to boot up a live CD or USB, mount your system's root partition, then copy /usr/lib to /mnt/{}usr/lib, but you will only get the default lib files and not what you may have added.

I think the best option is to reinstall the OS. Of course, you will want your data on a separate partition that is not formatted during install, good practice IMHO.

share|improve this answer

Supposing apt-get still works you can try to use dpkg to get a listing of the packages that have files there and then install them with apt-get. You can use this Ruby script, but the same idea can be implemented in python or bash:

raw_pkgs = `dpkg --get-selections`.split("\n")
pkg_list = []
raw_pkgs = raw_pkgs[0,100]
need_reinstall = []


raw_pkgs.each do |x|
    pkg = x.split(" ")[0]
    if `dpkg -L #{pkg}`.include? path
        puts "-> #{pkg} has files in #{path}"
        need_reinstall << pkg
puts "\nYou need to reinstall #{need_reinstall.size} packages:"
puts "\tsudo apt-get install --reinstall " + need_reinstall.join(" ")

It is a little of a brute-force solution and will take some time (in my system the listing was ~65% of the total packages installed...), but should work.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.