0

Is there a way to recover removed files in a situation such as described below? The command I executed was:

root@system:/# rm -r /tmp/letsencrypt.sh-XXXXXX l*

I tried to remove all the files in that directory that started with an l. When I noticed what I did it was too late, I know, pretty stupid...

I quickly made a snapshot after. Does anyone know some way to save my system? Or how I can search for files in it? It seems ls is also gone:

root@system:/# ls /tmp
bash: /bin/ls: No such file or directory

root@au-dev:/# echo *
bin boot dev etc home initrd.img media mnt opt proc root run sbin snap srv sys tmp usr var vmlinuz
oscrx
  • 1
  • 3
    Bad news: you need to reinstall your system. You have deleted every file in the system that starts with 'l', including all program libraries (typically starting with 'lib'). – Jos Jun 20 '16 at 18:16
  • 3
    Use a live USB, choose "Try Ubuntu", and back up all your user data to a safe place. Then reinstall Ubuntu. – Jos Jun 20 '16 at 18:18
  • Follow Jos comment and re-install without formatting any of the partitions. If it works you get your system back. Otherwise do a re-install with a restore of said backup – Rinzwind Jun 20 '16 at 18:25
  • 4
    Please [edit] your question and show us the output of cd /; echo *. I don't see why that command would have removed ls. It would have removed all your /lib directories, effectively breaking your system, but all of your data and files should be fine. – terdon Jun 20 '16 at 18:25
  • I thought that was interesting too, @terdon. I can confirm, that command does remove ls, and the l* directories. –  Jun 20 '16 at 19:51
  • Well, I should add, it doesn't remove ls from /bin but it does make the command not work. –  Jun 20 '16 at 19:54
  • i am trying to start it with the ubuntu iso, normal start gives (as expected) a kernel error – oscrx Jun 20 '16 at 20:00
  • Yeah, a livecd, should get you what you need. I'm playing with a system where I deleted lib, and practically nothing works, but everything but /l* is untouched. –  Jun 20 '16 at 20:04
  • unfortunately, its on a really old pc, a bit slow, but it is great to hear that the files are rescuable, just got my lets encrypt script working for a ubiquity unifi controller – oscrx Jun 20 '16 at 20:17
  • @bc2946088 oh, sure, it will break the command. It just won't remove it. – terdon Jun 20 '16 at 20:50
  • @oscrx: If my answer was helpful to you, then please consider marking it as the accepted answer so others may more easily find it in the future. This is also a polite way to thank the person answering your question for helping you out. – Andrea Lazzarotto Aug 12 '16 at 21:18

1 Answers1

0

Is there a way to recover removed files in a situation such as described below?

Technically, yes for example using testdisk. However, it is not worth it. You basically deleted some system files (the entire /lib and /lib64 directories) but not your user data.

Therefore, you are better off just making a copy of your home directory and reinstalling from scratch. I have described how to back up files using a live CD in this answer, here's an excerpt:

Backup using a live DVD or USB

If you have access to a Ubuntu installation medium, do the following:

  • boot your computer using the live DVD or USB
  • connect the external hard drive
  • run sudo nautilus in the terminal
  • copy all the files you want in the external drive
  • safely disconnect the drive
  • re-install Ubuntu