13

How we I undo the rm -rf command?

For example, I have an Application folder and I removed it with:

rm -rf Application

But it was my mistake and want to recover that Application folder, but it's not in Trash folder.

What should I do now? Is there any command to undo rm -rf?

Olivia Stork
  • 4,660
  • 5
  • 27
  • 40
Amrit Dhungana
  • 4,371
  • 5
  • 31
  • 36
  • I recommend it : http://stackoverflow.com/questions/21026636/recover-deleted-folders-from-debian-system/21027715#21027715 – MLSC Jan 23 '14 at 05:14
  • 1
    In principle you cannot undo `rm` (or [unlink(2)](http://man7.org/linux/man-pages/man2/unlink.2.html) which it would call). Learn to make backups, and to use [version control](http://en.wikipedia.org/wiki/Version_control) systems (like [git](http://git-scm.com) ...) for your source files. – Basile Starynkevitch Jan 23 '14 at 05:56

1 Answers1

22

Short answer: you can't¹. Files that get unlinked are irreversibly gone. If you really cared about what you deleted (e.g. personal files that cannot be reproduced), you could run photorec and try to recover as many files as possible, but you will loose any directory structure and naming.

Anyway, since you deleted the Applications folder, reinstalling everything could be the simple way to go. Provided that Applications folder contained installed applications.


1: some filesystems (will) support undeletion, but it's not your case.

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
  • What filesystem support undeletion or will do? Does ext4? – Tim Mar 25 '15 at 02:21
  • FAT16 notably does. Undeletion was planned for EXT4, but has never been implemented afaik, also because EXT4 is being phased out in favour of BTRFS. Anyway, there is an external tool for undeleting files on EXT3/4, [extundelete](http://extundelete.sourceforge.net/). – Stefano Sanfilippo Mar 29 '15 at 16:38
  • @StefanoSanfilippo the `extundelete` tool saved my life. I accidentally deleted all files from my `home` (in my case, by typo `rm -rf ~`), however, the `extundelete` recovered some important files (certificates, invoices, large virtual machine files etc.) into a folder called `RECOVERED_FILES`. Thanks for indicating it! – silvioprog Jun 01 '18 at 17:48