If you need to recover deleted files, it's imperative that you immediately shut down the newly installed system and not use it. You can run from a live CD provided that swap is disabled. See the guidelines here.
However, most of the time, its better to replace the contents of /usr/local
then to attempt recovery. At least if you were using /usr/local
in a normal way.
Ordinarily, /usr/local
is used for installing software that you've compiled yourself from source code. If you have only (or mostly) used it for this purpose, then you should just reinstall the software (i.e., re-create /usr/local
and build and install the programs and/or libraries like you built and installed them before).
This will very probably be less work, and take less time, than trying to recover the contents. And it will definitely be more reliable. Data recovery is appropriate when you have lost information that you want to retrieve--like the contents of a document that has not been backed up. But it will not reliably give you back exactly all the files you had before, where you had them before.
If you used /usr/local
in the usual way, then you should just rebuild its contents.
If you don't remember what was there, that might make it hard for you to rebuild it. But it would make it even harder for you to recover it; it's very difficult (often, impossible) to recover deleted files if you don't know much about them).
If you never used it at all, then there's probably nothing of consequence there. So if you don't remember ever using /usr/local
for anything, you can just recreate it with sudo mkdir /usr/local
and do nothing else. (Its subfolders will still be missing, but anything that uses them will typically create them if they are found not to exist, so that's usually not a problem.)
Preventing this in the Future
This addresses the updated portion of the question.
Comparison of File Deletion Safety Features in Ubuntu and Windows
The feature you're looking for would probably be more similar to System Restore in Windows, than to the Windows recycle bin. After all, when you delete files on the desktop in Ubuntu, they are sent to the trash (unless you indicate that they are to be permanently deleted, for example by pressing Shift+Delete). In the trash, they can be deleted for real (by emptying the trash) or they can be taken out of the trash. This behavior is identical to the recycle bin in Windows.
In both Windows and Ubuntu, when you delete files from the command-line, they are truly deleted. (That doesn't mean they are unrecoverable, but it usually means they are hard to recover and likely have unrecoverable parts.)
While Ubuntu and Windows both have a logical storage area for files that are marked for deletion (the trash and the recycle bin), Ubuntu does not have any feature that corresponds to System Restore in Windows.
Make Backups
If you need to safeguard against losing any data, your guess is totally right: backups are the correct solution. However, this is not a particularly "weak place" in Ubuntu; you can severely damage any part of your system by running rm -r
as root! (Running deltree
as an administrator in Windows is similarly dangerous.)
Avoid Any Unnecessary Operations on System Directories
Moving or renaming system directories is rare and usually unnecessary. I recommend avoiding performing any action on a top-level system directory unless you need to, especially if you cannot tolerate breakage.
Avoid -r
Except When Necessary (there is no such thing as mv -r
)
Unlike the rm
command, the mv
command does not have any -r
flag (see man mv
for details). You do not need such a flag, even to move a non-empty directory. If you avoid using -r
for commands where it's not needed, and be extra-careful in the minority of instances where you do use -r
, you may be able to reduce your risk of data loss or other undesirable changes to your system.
Use gksudo nautilus
(carefully!) if you want to trash instead of delete system files.
You can open a root
file browser window by running gksudo nautilus
. (In some later versions of Ubuntu, gksudo
is not always installed. You can get it by installing the package gksu
, or you can use sudo -H
in its place. You should not use plain sudo
to run graphical programs.) This gives you a graphical file-browsing interface with essentially unlimited power.
This carries its own dangers, and I don't think it's really safer than the command line. However, when you remove a file, it should go to the trash rather than being truly deleted. It will go to the root user's trash--not your regular user account's trash can. You can access the root user's trash from within that same root file browser window.
Sending files to the trash as root is not a very common operation, so I recommend making sure it works with an unimportant file (perhaps one you create for testing), and that you can restore the test file, before relying on this behavior of the system.
If you choose to use a root file browser window, please remember that, like when running commands with sudo
, a mistake can have systemwide consequences. Also, any program you run from a root file browser window will itself run as root. For these reasons, I recommend always closing a root file browser window immediately, once you are doing using it.
tomcat7
– catch23 Aug 13 '13 at 22:06tomcat7
from source, you can do so again. – Eliah Kagan Aug 13 '13 at 22:08