Made a big(?) mistake with `mv /*/*/* ./`
from joeldebruijn@lemmy.ml to linux@lemmy.ml on 07 Jun 07:24
https://lemmy.ml/post/31302258

Background:

I think I messed up … Wanted to get a lot of files out of a nested folderstructure 3 levels deep and used mv /*/*/* ./ somewhere deep in my personal folders. I got a lot of errors and quick as I could stopped it. Now that folder is is messed up with a lot of stuff (see below) which I dont know the origin of. The good news: I have fairly recent backups

Questions:

Any help greatly appreciated.

Files:

Sorry for the long list

0 1 10 10:1 10:125 10:126 10:127 10:130 10:183 10:224 10:228 10:229 10:231 … 116:8 116:9 … 13:81 … 8 81:0 81:1 81:2 81:3 9 arch_status attr autogroup by-diskseq by-id by-label by-partlabel by-partuuid by-path by-uuid cgroup cmdline comm coredump_filter cpu_resctrl_groups cpuset fd fdinfo fonts gid_map grubenv limits list.txt locale loginuid map_files maps mountinfo mounts net ns numa_maps nvme0n1p8_crypt oom_adj oom_score oom_score_adj projid_map sched schedstat sessionid setgroups smaps smaps_rollup stat statm status task timens_offsets timers timerslack_ns uid_map unicode.pf2 usb wchan x86_64-efi

#linux

threaded - newest

dengtav@lemmy.ml on 07 Jun 07:37 next collapse

I think there is a typo in the path in the body of your post, or?

joeldebruijn@lemmy.ml on 07 Jun 07:41 collapse

Yeah, I see, command wildcard asterix being markdown bold. Original command:

<img alt="" src="https://lemmy.ml/pictrs/image/8309ba90-2f2b-4097-8745-1e5276d5cd7b.png">

tgt@programming.dev on 07 Jun 07:50 next collapse

You moved everything down 3 dirs from root to your working dir.

joeldebruijn@lemmy.ml on 07 Jun 07:57 collapse

Ouch … feel so stupid.

ogeist@lemmy.world on 07 Jun 08:40 next collapse

Anything user accessible, so not that bad. Restore one backup up and move from there.

atzanteol@sh.itjust.works on 07 Jun 12:35 collapse

I once ran ‘chown -R root:root /’ in a misguided attempt to solve some permissions issues I was having. 0/10, do not recommend. It turns out a lot of system things aren’t root owned…

Running a stupid command and learning from it is part of the learning process.

mina86@lemmy.wtf on 07 Jun 09:54 next collapse

Use backtics to quote code fragments. Tripple backtics to block quote. You should be able to edit your post.

joeldebruijn@lemmy.ml on 07 Jun 10:01 collapse

Oh that worked, thnx!!

mina86@lemmy.wtf on 07 Jun 11:50 next collapse

What you have in title of the post, body of the post and in this screenshot all disagree with each other.

joeldebruijn@lemmy.ml on 07 Jun 12:02 collapse

Ah, keen eye, corrected the title and body text to match the screenshot. (From terminal history so I think thats what I actually ran)

[deleted] on 07 Jun 11:58 collapse

.

Theoriginalthon@lemmy.world on 07 Jun 07:41 next collapse

If you did it as root probably broken, if not it should be ok, you might just get programs behaving weirdly.

joeldebruijn@lemmy.ml on 07 Jun 07:42 collapse

Ah, I was no root … that should lower the impact …

Theoriginalthon@lemmy.world on 07 Jun 07:52 collapse

It looks like you grabbed stuff from /dev which I think can’t be moved, it’s created and managed by the kernel

Quazatron@lemmy.world on 07 Jun 09:17 next collapse

Mark it as an achievement on your learning path and move on. We all did something silly like that at some point.

Great that you have backups, get a fresh install and restore it.

Lessons learned: don’t work as root unless you absolutely positively have a good reason to do so.

joeldebruijn@lemmy.ml on 07 Jun 09:30 next collapse

I only have a backup of my own personal files, not of the whole system. So my question about impact is about not having to do a fresh install.

Also I have dual boot and grub etc do scare me. 😁

I didnt work as root by the way …

Quazatron@lemmy.world on 07 Jun 14:10 collapse

I always treat the system as discardable and only backup the /home and /etc directories. Saving those, I can afford to wipe the system and re-settle on a new distro if I want to.

Of course if you throw Windows into the mix, all bets are off. Personally, I stay the hell away from that.

joeldebruijn@lemmy.ml on 07 Jun 14:35 collapse

Yeah agree, its a work provided laptop, they allowed local admin etc but require Windows (at least that is) so just glad they gave me a HP laptop with 500GB SSD and for me certain freedom to configure dual boot etc

pewpew@feddit.it on 07 Jun 09:48 next collapse

I have the habit of holding shift everytime I delete something, one day I’ll learn the hard way not to do it

FauxLiving@lemmy.world on 08 Jun 17:18 collapse

root@desktop:/# chown -R user:user / home/user
root@desktop:/# 

<img alt="" src="https://lemmy.world/pictrs/image/2b09f6bf-86fd-49a1-8778-616e9002900d.jpeg">

e: sidenote. if you’re using markdown for codeblocks you can add the language name after the first three backticks to change the syntax highlighting in the codeblock. TIL

merthyr1831@lemmy.ml on 07 Jun 10:54 next collapse

I’d probably do a clean install (eventually) even if it looked like stuff works for now.

I know the pain, though. did rm -rf in the wrong directory and wiped half my drive in seconds. Good times.

phantomwise@lemmy.ml on 07 Jun 19:46 next collapse

Ouuuuch 😬

thingsiplay@beehaw.org on 08 Jun 04:36 collapse

Classic. I also did the rm -rf once in a wrong directory of a programming project. Luckily it was a subdirectory, so nothing important lost. But it could have easily if I was one hierarchy higher.

I am so much afraid of rm -rf, that I usually go in a directory with cd and rm in current directory those files only. And then I do rmdir on empty directories. I use recursive -r only, with specific directory names included (autocomplete helps). This way, even if I am in the wrong directory, the chance that there is the exact same directory name is a bit lower.

And I often also just switch to graphical filemanager to delete files. Not only that. Sometimes I also just move folder instead deleting, so I have a back up until I’m sure. There is also trash-cli.

ascense@lemm.ee on 07 Jun 11:03 next collapse

Unless you ran the command as root, on a standard install it should really only be able to touch your home directory and any disks you may have had user mounted under /media.

gonzo-rand19@moist.catsweat.com on 07 Jun 11:14 next collapse

If ./ and ./*/*/* are both within your home folder, you should just restore it from your backup. The command you ran takes everything up to 3 levels deep and moves it up to the working directory, and unraveling that will be a pain in the ass.

joeldebruijn@lemmy.ml on 07 Jun 12:03 collapse

If the actual command was this … mv /*/*/* ./ would moving stuff out of /boot or /dev folders make more sense?

joeldebruijn@lemmy.ml on 07 Jun 12:10 next collapse

Strange thing is, instead of moving folders (which isnt possible without root anyway) it looked like some of them got copied instead. Compared some folders from /boot/grub with the dump in my homefolder and they were the same files (number and names etc).

crater2150@feddit.org on 08 Jun 23:05 collapse

My theory for why it created copies: The files you listed look like they are all subdirectories from /dev, which is (usually) a separate filesystem. When you try to move a file or directory across filesystems, the OS can’t just change the link, it has to actually copy the files and then remove the original. As a directory is a set of links to files, and the copies are different files, directories are just newly created with the same name in the new location instead of copying the directory filesystem entry. It looks like mv creates these target directories, before it checks if it actually has permission to remove the source, but checks file permissions, before it copies them

joeldebruijn@lemmy.ml on 09 Jun 10:20 collapse

That … makes a lot of sense, thanks 🙏🙏

gonzo-rand19@moist.catsweat.com on 07 Jun 14:05 collapse

I can't say because those paths are relative and I don't know your file structure. That said, even if I did, restoring from backup would take out all of the guesswork here so I would recommend that over trying to do it manually.

Enkers@sh.itjust.works on 07 Jun 18:37 collapse

Just a quick clarification: /*/*/* is not a relative path. The first / references the root directory.

gonzo-rand19@moist.catsweat.com on 07 Jun 19:39 collapse

You're right. I thought it was ./*/*/* instead.

joeldebruijn@lemmy.ml on 07 Jun 12:06 next collapse

I took a deep breath (was not being root, how bad could it be?) and rebooted. Luckily everything seemed fine.

Grub letting me choose between Debian and Win11 (its a laptop from my employer) and both booted if choosen. Thanks for all the advice.

oshu@lemmy.world on 07 Jun 12:35 collapse

If you ran this as a non-root user then you didn’t move any system files you just made some copies. Delete the new copies and you should be fine.

joeldebruijn@lemmy.ml on 07 Jun 12:59 collapse

Got chills down my spine initially but was a “good” scare … the one which makes me carefull next time before any real damage is done. 🙈👍

Czele@lemmy.world on 08 Jun 07:17 collapse

Good thing everything is now fine. For the next time You use ‘mv’ or ‘cp’ or ‘rm’ and so on, replace this with ls to see what files abd folders You are about to move, remove, copy

joeldebruijn@lemmy.ml on 08 Jun 08:02 collapse

Oh never thought about using ls to “test” things, thnx!