Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

I accidentally issued 'sudo rm -rfd *' in the /usr/local directory. What would I have to do to at least get it back to how it would be from a fresh install (Linux Mint 15)?

share|improve this question

marked as duplicate by Mokubai, Shakehar, Breakthrough, Baarn, Carl B Sep 10 '13 at 4:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

/usr/local usually contains files from applicatons not installed using the package manager. If you didn't do this, it was probably empty, other than the top level directories. –  Paul Sep 6 '13 at 13:10
add comment

2 Answers

Don't ever try to recover system files

Oh please, don't ever recommend file recovery for system files! File recovery can be attempted on more unique files like a text you've written yourself.

Recovering system files is begging for troubles.

1st Solution

For your system, just reinstall it. You don't need to wipe/format anything during the installation: everything missing will just be replaced. You will just have to upgrade as usual.

But this shouldn't be necessary as /usr/local is most certainly empty on your system.

2nd Solution

Usually, there is almost nothing in that folder. If you know that you have installed something there, just reinstall it.

Finally, some packages might have put some files in there. Just open a terminal and check that the following commands outputs nothing:

dpkg --get-selections | cut -f 1 | xargs dpkg -L | grep /usr/local


What it does is pretty simple:

dpkg --get-selections 

will output the list of the packages installed on your system in the format:

package_name                      installed

But we only want package_name for each line:

| cut -f 1 

| tells bash (the program that runs in the terminal) that the output of the previous command should not be displayed but "piped" inside the next program (here cut).

cut, as its name implies will cut each line into words an keep only the first field (-f 1) that it will display.

To sum up,

dpkg --get-selections | cut -f 1

should return the list of the packages installed on your system.

Now we can pipe that list to xargs which acts like "for each element in the list do ...".


xargs dpkg -L 

will execute:

dpkg -L package1
dpkg -L package2
dpkg -L package3

for each package name that you give it through the pipe.

dpkg -L mypackage lists the files contained in the package named "mypackage".

And now, we just have to take that file list and check whether some package did put a file in /usr/local. We do it with grep which will filter out any output not containing /usr/local.

So, if we put it in order, first we get the list of installed packages, then we format this list to keep only the package names, then we list the installation folders used by the package, then we filter it to keep only what's inside of /usr/local.

If the command returns nothing, then you don't need to worry.

Graphical UI alternative

To my knowledge, there is no GUI alternative.

share|improve this answer
add comment

There is no need to reinstall the OS since the OS should not store anything in /usr/local or in /opt (these two are more or less the same).

However any programs you compiled yourself or which got installed via a package manager or the a ports tree might very well end up in /usr/local/.


  1. Check your backups. What was in those folders. Deinstall and reinstall those programs.
  2. Or, lacking backups, make a list of all installed packages and deinstall and reinstall them all.

(Use apt-get or dpkg -l to list the packages).

share|improve this answer
add comment

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