Ah! Deleted (almost all of) my home directory with the cp command??
My old laptop has basically kicked the bucket, and I tried to copy my home directory data to a flash drive with the cp -r command. It started spitting out some errors about not being able to copy symbolic links and so I ctrl-c'd the process. Then, when I looked at my home directory, the only thing left were the invisible directories (that start with periods). What happened? And can I get my data back?
About this post
- Posted
- Archived
- Score
- 3 · 57% up
- Kind
- Text
- ID
- 1844201
19 comments
Update: I entered "sudo rm * /mnt/usbdrive/" to clear the drive by mistake, while in my home directory. Lessons learned. I'll follow your advice, thank you.
Bro
Next time mkfs the thumbdrive .... That command does not need an *
yessir.
unless you have instant discard activated your files might still be there, there are recovery tools for such cases. Maybe you want to try and salvage some data... https://wiki.archlinux.org/title/file_recovery
Hahahah
If you can only see "dot files", sounds like you have either deleted or moved all visible files instead of copying them.
Nobody knows what you have done, tbh. Cp command is just copying files, it does not delete anything, so no way you have just issued a cp command.
If you have "moved" files (renamed) with mv, or deleted by a misstake, you may try some recovery software to see what you can get back. Data might still be there, is just not visible to the system unless you have also shredded it. If your hard drive is dying, your hard drive might be dead too, but what you describe sounds like you have either moved or deleted your files.
Good luck.
Boot into another machine and have a spare disk ready, then run photorec on your old drive and dump the data to your spare disk. If you don’t do anything else, you should be able to recover most of your stuff.
Running photorec on the drive directly is basically a death sentence for a drive that already has problems. Use ddrescue to get an image that you can make multiple attempts at rather than wasting your one opportunity on photorec
Well yeah if the drive is faulty it could die after you read it, but photorec won’t write to the drive your recovering from unless you tell it to. So it’s not necessary bad to photorec from the real device instead of an image. Guess it depends if you just accidentally deleted the wrong file or you genuinely have drive issues.
what’s the file system your home directory is using? what kernel version? what could you gather in
dmesg? these would help with diagnosisA long shot, and although it wouldn’t help other than understanding in hindsight, could it be that you swapped the intended order of cp’s arguments?
Always give exact command text you entered.
It's hard to imagine how
cpwould delete the source data.Early in my Linux journey, I was told to use a File Manager when you're new.
Good luck
It is most likely that your old drive has failed or is in the process of failing.
I've had this happen a number of times over the years working as a technician.
The hard rule is to always take a bitwise image of any suspect drive before doing anything else. If the device begins to fail during that process, switch to ddrescue to attempt to attain an image multiple ways.
Once you've got your image, you may be able to mount it and copy the files from there, if not you may be able to use testdisk/photorec to forensically carve the files from the image.
All of this however, is highly unlikely to actually recover the data in any useful form and is highly time consuming
Ouch! I figured, "cp" cannot do that much damage
no backup?
Say it with me everyone. Timeshift. Timeshift. Timeshift. Backup your data before doing anything that alters it in a way you think you might need to revert back from
Update: I've restored all of the data I think, and gotten all the f* files sorted by extension. It's not perfect but I'll be able to find what I need. Wow was I stupid with the command-line. Thanks for all the help.