ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
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.
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,479
Rep:
@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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.