Recover deleted images with standard Linux tools from the command line
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Research: Upon research I read about the following downloaded applications that would make this task a no-brainier:
- Testdesk
- Photorec
- etc
BUT the problem is I am required to use tools that came with the distro.
Quote:
Originally Posted by D-kikin
For the purpose of the assignment I am not allowed to install any tools. I must use the tools it came pre-installed with.
I'm not sure I understand a) what the point of this restriction is, or b) what it even means. Testdisk/photorec do not need to be downloaded from a random website, that's rarely how software is installed in Linux. They are included in the standard repository or extended repositories for almost all distros.
So what does "came with the distro" even mean? If it's available on the installation DVD but wasn't installed by default because of the installation type chosen by the user, did it "come with the distro" or didn't it? What if it's on the installation DVD but not the CD? Or what if the user did a net install? Or what if it's in the distro's standard repo but wasn't included on the DVD because of size restrictions?
If you simply mean that no tools can be installed on the machine that weren't already installed when the exercise began, then that simply means your success/failure in this project depends entirely on the type of installation the original user performed, which is a really stupid restriction. Also, what about booting a live distro and doing the recovery from there? testdisk/photorec come standard on all of the recovery distros.
I agree with rknichols - this exercise is so far removed from real life that it's pointless. I have done exactly what this exercise targets. I copied over some images from an SD card to my computer, deleted them off of the SD card, and then due to a small fubar in a processing script I accidentally deleted all of them off of the computer. I then used dd to create a backup image of the SD card, and ran photorec on that backup image, which recovered all of the images flawlessly.
Last edited by suicidaleggroll; 11-23-2015 at 11:58 AM.
If some of you use an internal SSD drive with TRIM enabled, recovering files is NOT possible. You CAN however recover files from USB drives and external SSD drives.
only if the user used the " move to trash" on the r-click menu
if DELETE on the r-click menu is used it is NOT moved to the trash cam
nor is it moved if the "rm" command is used or my preferred "srm" is used
recovery after srm would be "fun"
but recovery might be made easier or harder depending on the file system used
and recovery of a deleted folder is why i keep a "SystemRescueCD" around and a Knoppix cd
I went hunting for the trash folder but no luck. As root I ran, "find / -name T*" and no file name trash was listed. I looked at system info and found the following information:
The root filesystem for SliTaz is a tmpfs in RAM. Unless that user's image folder is located somewhere else on a conventional filesystem, there is nothing to recover.
Somehow I feel the point of this "assignment" is just to encourage some downloads of SliTaz.
The root filesystem for SliTaz is a tmpfs in RAM. Unless that user's image folder is located somewhere else on a conventional filesystem, there is nothing to recover.
Somehow I feel the point of this "assignment" is just to encourage some downloads of SliTaz.
But if files are deleted from the GUI, R-click on file, the distribution is configured to put those files somewhere. Where can I look to find out where those files are?
You can run this command to search for a trash directory and list the contents there in. The wildcards are used in case there are prefixes and suffixes in the directory name. The -iname will match both upper and lower case patterns.
Code:
find /home -type d -iname "*trash*" -exec ls -1 '{}' '+' | less
Or a system wide search
find / -type d -iname "*trash*" -exec ls -1 '{}' '+' | less
But as rknichols mentioned, if the whole filesystem was using tmpfs. All files are gone when you turn off the computer.
Last edited by phantomfreak; 11-29-2015 at 03:45 PM.
But if files are deleted from the GUI, R-click on file, the distribution is configured to put those files somewhere. Where can I look to find out where those files are?
You can always create a file, delete it from the GUI, then run "find $HOME -cmin -2" to find everything under your home directory that has been changed, renamed, or moved within the last 2 minutes. Then, look for the corresponding location in the other user's account. I do that sort of thing all the time to see where some GUI config tool stores stuff.
But if it were that simple, that user could have recovered the files from his/her trash. I suppose you could see whether your CLI "rm" command is aliased to something that saves deleted files ("type rm" or "type -path rm"), but that isn't standard in SliTaz.
[EDIT] Arrgh! The crippled find command in SliTaz doesn't have "-cmin". Here, the trash bin is in ~/.local/share/Trash/files/ . But as I indicated above, this would have to be a user that lacks the ability to click on the "Trash" icon on the desktop to recover deleted files.
Last edited by rknichols; 11-29-2015 at 03:55 PM.
Reason: Arrgh! ...
You can run this command to search for a trash directory and list the contents there in. The wildcards are used in case there are prefixes and suffixes in the directory name. The -iname will match both upper and lower case patterns.
Code:
find /home -type d -iname "*trash*" -exec ls -1 '{}' '+' | less
Or a system wide search
find / -type d -iname "*trash*" -exec ls -1 '{}' '+' | less
But as rknichols mentioned, if the whole filesystem was using tmpfs. All files are gone when you turn off the computer.
You can always create a file, delete it from the GUI, then run "find $HOME -cmin -2" to find everything under your home directory that has been changed, renamed, or moved within the last 2 minutes. Then, look for the corresponding location in the other user's account. I do that sort of thing all the time to see where some GUI config tool stores stuff.
But if it were that simple, that user could have recovered the files from his/her trash. I suppose you could see whether your CLI "rm" command is aliased to something that saves deleted files ("type rm" or "type -path rm"), but that isn't standard in SliTaz.
[EDIT] Arrgh! The crippled find command in SliTaz doesn't have "-cmin". Here, the trash bin is in ~/.local/share/Trash/files/ . But as I indicated above, this would have to be a user that lacks the ability to click on the "Trash" icon on the desktop to recover deleted files.
But as rknichols mentioned, if the whole filesystem was using tmpfs. All files are gone when you turn off the computer.
Presumably the boot process for this VM sets up the filesystem as though those image files had been created and deleted. If they were deleted via a GUI file manager, then there would be some sort of trash folder. If they were actually unlinked (via rm), then the tmpfs would no longer have any record of their content. Those data blocks would have been released back to the kernel's free memory pool and no longer recoverable except by extraordinary means (freezing the VM and using forensic tools on the host to examine its memory -- that sort of thing).
Last ditch would be to run a "find . -type f" in that user's home directory and see of anything that looks like image files shows up. Frankly, I doubt that will discover anything.
As a final attempt to see what is going on, what is the output from "cat /proc/mounts"?
Filesystem Size Used Available Use% Mounted On
rootfts 908.9M 457.7M 451.2M 50% / tmpts 908.9M 457.7M 451.2M 50% / tmpts 504.9M 0 504.9M 0% /dev/shm
The / filesystem which includes the home directory is running in ram via tmpfs. So, theoretically, anything the OP did within slitaz is erase when the machine has turn off.
I have an SSD drive and to limit the writes to extend the life of my drive, I have /tmp and /var/log running in a tmpfs filesystem.
When I turn off the computer, all files in /tmp and /var/log are gone. And newer files with the current date are created when the system reboots.
Another idea the OP could have done beforehand is used a sticky bit for the Image directory. If users were given permissions to write to this directory, the sticky bit can prevent other users except root from deleting other user's files. However, sticky bit isn't useful on a tmpfs filesystem unless you keep the machine on 24/7.
I downloaded siltaz 5.0rc3 and ran it in a VM to prove my assumption that a tmpfs filesystem does not keep the created files and directories once the system or VM is shutoff.
Upon booting, siltaz 5.0 has a trash folder on the desktop. From the GUI file manager, I created some files and deleted them by right-clicking on the files. A dialogue opened up and I selected Move to Trash. Upon doing this, the deleted files were in the trash folder.
The second test was to reboot the VM and to see if the deleted files and the Trash directory will be retained.
When the system was up and running again the deleted files in the Trash folder were gone as well as the ./.local/share/Trash directory.
Below are two images of the siltaz desktop. The first one shows the trash folder icon with files in it. I also ran three commands df , uname , and find to show the existence of a Trash directory in the user's home folder.
The second image shows the siltaz filesystem after the reboot. The deleted files are gone from the trash icon as well as the ./local/share/Trash directory.
As you can see, a filesystem using tmpfs is not permanent. Anything you do or create is gone on the next reboot. If you or the other party had installed siltaz on a virtual disk in a VM, this may have been a different story and possibly be able to recover the files.
I'm afraid if you did ran siltaz with a tmpfs filesystem and created some files and then rebooted. Those files are gone.
Last edited by phantomfreak; 11-29-2015 at 09:47 PM.
Basically you need to unmount the partition (unmount cmd as root user), but this only works if nothing is using it, else it'll say 'filesystem busy...' or similar.
Its good for you to learn about tools that theoretically can recover files, but in the real world you'd normally rely on backups, especially for a shared or server system.
Unmounting and/or shutting down a system may not be an option.
(PS that's not a typo; the unmount cmd really does not have an 'n' in the name )
does this work the same to Android phone? I need to recover a few photos on my Galaxy S6
does this work the same to Android phone? I need to recover a few photos on my Galaxy S6
With a simple google search there are ways to do so. You'll need to read each link and see which is more doable for you. Some links will use windows based tools or linux based tools. Also, some instructions will be specific to internal, external or both.
Last edited by phantomfreak; 11-30-2015 at 03:20 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.