LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-26-2015, 02:12 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Rep: Reputation: 52
How can I recover deleted directory?


Could anyone point me to info on how to recover a deleted directory? I have modified files for a few days since the last backup and I have done nothing on the machine since so the files should still all be there.

The file system is ext4 and what I have done was:
Code:
rm -rf *~ /dir/subdir/mydir
thinking that would remove the backup files from mydir and its subdirectories but
Code:
mydir
is gone

Thank you for your help.
 
Old 05-26-2015, 02:39 AM   #2
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
I have found
Code:
extundelete
is part of the distro and I am going to try it and report the result.
 
Old 05-26-2015, 11:24 AM   #3
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,479

Rep: Reputation: Disabled
Never use the -rf with rm unless you are sure of the outcome.

Good luck with extundelete, I've never heard of it, let us know how it goes.

This should do what you wanted to do
Code:
cd /dir/subdir/mydir; rm *~
(Always safer to go into the directory to do deletions.)
 
1 members found this post helpful.
Old 05-27-2015, 12:42 AM   #4
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
I edit many files in many directories and it is time-consuming to do
Code:
rm *~
from each directory, I think it would be better to make a bash script (without using "f") that does the job and invoke it every time I need to remove those backups. The problem is in typing many times the same thing and making a typo which is only discovered after having pressed "Enter", the danger seems to be almost the same to me if I accidentally type
Code:
rm *
"extundelete" recovered many files, there was probably close to 20 files that had been changed since the last backup and I could not remember the filename of some of them, I still have to compare those recovered to those from the backup to find which had been changed, a few known changed files were recovered, one important file was recovered while another important file just created (no backup) is missing, I anticipate it has been overwritten by a process because it took me a few minutes to realise what I had done before I logged out and back in as another user to protect the partition. "extundelete" put all the files recovered in a "lost-and-found" sub-directory with all the correct file-names.

I then tried "foremost" to try to recover the missing new file but it did not recover much and it was mostly garbage, "foremost" has a list of mime types of files it is able to recover, text files not being one of them and all my files were text files, I tried the "htm" option with no better result.

I then tried "scalpel" which recovered many more files than the other 2 but no text files, the recovered files are given a new incremental numeric name which means you need to display each to find what it is. There are occasionally many copies of the same file, all small files, something I cannot explain

I read it may be possible to recover files using "dd", is there anyone who could advise on this? I have never used it and I found the man pages never give enough information for my level of experience. I know the name of the missing file and the day it has been created if that could be of any help

Last edited by rblampain; 05-27-2015 at 12:48 AM. Reason: clarity
 
Old 05-27-2015, 12:56 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

if you don't want the backup files you should disable their creation. What text editor are you using?

Or remove them with find. Eg to just list the files
Code:
find /dir/subdir/mydir -name '*~'
Then once you are sure these are the files you want to delete, you can delete them with:
Code:
find /dir/subdir/mydir -name '*~' -delete
Evo2.
 
1 members found this post helpful.
Old 05-27-2015, 01:00 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Quote:
Originally Posted by rblampain View Post
I edit many files in many directories and it is time-consuming to do
Code:
rm *~
from each directory
What is really time consuming: to restore your files.
As it was mentioned if you want to remove a lot of files/dirs, first just collect them into a file (line by line), check the content carefully and finally insert an rm at the beginning of the lines in that file and execute that as a script.
 
1 members found this post helpful.
Old 05-27-2015, 01:07 AM   #7
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
configure your editor to put this backup files somewhere else
or turn this feature off
 
1 members found this post helpful.
Old 05-27-2015, 02:57 AM   #8
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,479

Rep: Reputation: Disabled
@rblampain
Thanks for the feedback about extundelete.

The use of dd is for copying a disk block by block, not file by file.
I think what you may have read was about making a backup of your disk, & then working on that backup, not the actual disk.
 
1 members found this post helpful.
Old 05-30-2015, 10:14 PM   #9
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
I used "gedit".

I introduced a mistake in my backup procedure, I deleted the backup files (*~) before making the real backup, I should do this after. I do not really want to disable the option.

I work as 7 different users on this testing machine and need only to make a backup after having worked as that user which could be months apart, hence a usual daily backup is not really what I need.

Thanks to fatmac, evo2, pan64 and a4z, having a script on those lines is precisely what I need.

What I found on the Internet: recovering a deleted directory and its files is technically impossible, only recovering files is possible and, in practice, many of those files may not be from the deleted directory which may make the job tedious especially if the recovery tool gives the files a different and incremental name.

Last edited by rblampain; 05-30-2015 at 10:18 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recover deleted username directory leblinux Linux - Newbie 1 10-21-2011 09:30 AM
Recover deleted directory in EXT3 Snigger Linux - General 1 07-20-2011 09:01 AM
How to recover deleted directory in Ubuntu 8.04? joulaei Linux - Newbie 3 02-08-2009 02:44 PM
Deleted a directory! Can I recover it? 360 Linux - General 2 02-11-2003 11:23 AM
Deleted Directory, how to Recover ?? GT I.N.C Linux - General 5 11-19-2002 08:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration