I did something stupid on a remote linux server:
- my working directory was
/some/directory - I ran
for dir in $(ls | grep "a_pattern"); do mv $d/* ./my_subdirectory; done - Now
/some/directory/my_subdirectorycontains things likebinbootdevandhome, which are definitely not supposed to be there
Feel free to point out how stupid #2 was. If I understand my error correctly, $d was empty (I meant to type $dir -- maybe even with that fix it would be a poorly-crafted command, but I should close this parenthesis), so basically the command I ran was mv /* ./my_subdirectory.
When I realized what I'd done I hit ctrl-c ctrl-c, so the command was interrupted before it finished.
My question has two parts: first, what should I do to fix this; and second, did my command actually move things out of /, or did it just copy them?
I did run mv, do I'd expect it moved things, and yet I don't see anything under ./my_subdirectory which is missing from /. Let me know if I'm being unclear here. For example, /some/directory/my_subdirectory/bin contains bash, cat, mount and mkdir, but those programs are still present under /bin, as if they were copied and not moved. Why is that? Can I safely delete everything under /some/directory/my_subdirectory, or would that be a terrible mistake?
Following tad's suggestion in the comments, here is some of the output from find ./my_subdirectory -type f:
./my_subdirectory/bin/umount ./my_subdirectory/bin/date ./my_subdirectory/bin/sort ./my_subdirectory/bin/red ./my_subdirectory/bin/dumpkeys ./my_subdirectory/bin/sleep ./my_subdirectory/bin/readlink ./my_subdirectory/bin/mv ... ./my_subdirectory/etc/security/pam_env.conf ./my_subdirectory/etc/security/chroot.conf ./my_subdirectory/etc/security/access.conf ./my_subdirectory/etc/security/namespace.init ./my_subdirectory/etc/security/group.conf ./my_subdirectory/etc/security/console.handlers I checked and those files still exist under /etc and /bin. When I run diff ./my_subdirectory/etc /etc I get common subdirectories, some that are only in /etc, but nothing that is only in ./my_subdirectory/etc. So it seems that things were copied rather than moved. Is that to be expected given that I did not run the mv command as sudo?
find ./my_subdirectory -type fwhich will show you what was moved.find. I did not run mymvcommand as sudo, by the way, in case that's relevant.