Skip to content

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?

3 points18 comments
Open on Reddit
About this post
Posted
Archived
Score
3 · 57% up
Kind
Text
ID
1844201

Author

2
posts
4
comments
1
media
View profile

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.

25 points

the only thing left were the invisible directories (that start with periods)

If you can only see "dot files", sounds like you have either deleted or moved all visible files instead of copying them.

What happened?

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.

8 points

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.

2 points

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

6 points

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.

1 points

what’s the file system your home directory is using? what kernel version? what could you gather in dmesg? these would help with diagnosis

2 points

A 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?

2 points

Always give exact command text you entered.

It's hard to imagine how cp would delete the source data.

Early in my Linux journey, I was told to use a File Manager when you're new.

Good luck

2 points

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

1 points

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

1 points

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.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.