How to recover the deleted files using "rm -R" command in linux server? [closed]
Asked Answered
F

3

30

I have unfortunately deleted some important files and folders using 'rm -R ' command in Linux server.

Is there any way to recover?

Foppish answered 3/11, 2014 at 19:24 Comment(4)
Try Super User.Wanwand
@Wanwand Unix & Linux will be betterCrimson
U can use "rm-trash" utility from github.com/nateshmbhat/rm-trash . It puts the files into trash and handles duplications , permissions etc.Irkutsk
I wonder if you can alias rm -rf to mv /tmp? Although there might be consequencesKoblenz
M
49

since answers are disappointing I would like suggest a way in which I got deleted stuff back.

I use an ide to code and accidently I used rm -rf from terminal to remove complete folder. Thanks to ide I recoved it back by reverting the change from ide's local history.

(my ide is intelliJ but all ide's support history backup)

Missionary answered 17/3, 2016 at 11:6 Comment(9)
I'd give this a million upvotes! Just saved me from loosing a days work because of a stray rm..Howenstein
same if one is using git. you can use git reset --hard HEAD to get all your files backPassepartout
On Windows, with WebStorm 2017.2: select the folder that contained what you deleted, then in menu VCS..Local History..Show History you can find the file you deleted, select it, then click the Revert Selection button in the toolbar. Thanks, saved me some time!Census
Idea saved me from doing double work Thank you so muchReasoning
I can confirm this worked in Eclipse as well after i deleted a file with rm.Spitsbergen
Same thing applies to Eclipse IDE. Just right click on the project (hopefully you haven't deleted it!) and choose Restore from Local History... This saved me from rewriting two days worth of coding!Aetiology
you were a using a code repo from git right? or was in unversioned files?Planarian
Confirm this with Eclipse 2020-12 (4.18.0) even with a deleted repo. I accidentally rm a repo. After checking the repo out again and waiting for some seconds, the local history was available! THANKS!Therianthropic
What about Visual Studio Code-- any such known way to get back files deleted with rm ?Calistacalisthenics
K
18

Short answer: You can't. rm removes files blindly, with no concept of 'trash'.

Some Unix and Linux systems try to limit its destructive ability by aliasing it to rm -i by default, but not all do.

Long answer: Depending on your filesystem, disk activity, and how long ago the deletion occured, you may be able to recover some or all of what you deleted. If you're using an EXT3 or EXT4 formatted drive, you can check out extundelete.

In the future, use rm with caution. Either create a del alias that provides interactivity, or use a file manager.

Keare answered 3/11, 2014 at 20:38 Comment(1)
I found trash-cli quite nice for "or use a file manager". What's better than trashlib inside rm command? extundelete sounds good to, it's better than manually recovery from journal :), thxStubblefield
N
3

Not possible with standard unix commands. You might have luck with a file recovery utility. Also, be aware, using rm changes the table of contents to mark those blocks as available to be overwritten, so simply using your computer right now risks those blocks being overwritten permanently. If it's critical data, you should turn off the computer before the file sectors gets overwritten. Good luck!

Some restore utility: http://www.ubuntugeek.com/recover-deleted-files-with-foremostscalpel-in-ubuntu.html

Forum where this was previously answered: http://webcache.googleusercontent.com/search?q=cache:m4hiPw-_GekJ:ubuntuforums.org/archive/index.php/t-1134955.html+&cd=1&hl=en&ct=clnk&gl=us

Necrotomy answered 3/11, 2014 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.