Instead of "mv filename.sql newfolder" I did "mv filename.sql /newfolder" and wiped out a bunch of files?

1

Like I said, I moved a bunch of sql files but instead of moving them to a directory I seem to have renamed them and put them all in the root directory as one file named "newfolder"

Can I undo this or have I royally boned myself?

GUYMESSEDUP

Posted 2013-03-06T06:27:48.830

Reputation: 11

1If you ran mv filename.sql /newfolder you didn't rename more than one file. Just run mv /newfolder filename.sql to revert. – slhck – 2013-03-06T06:32:23.667

I ran it a bunch of times without checking. So I ran "mv filename1.sql /newfolder" then "mv filename2.sql /newfolder" then "mv filename3.sql /newfolder". So I overwrote the file a bunch of times. It it at all possible to fix. – GUYMESSEDUP – 2013-03-06T06:40:45.517

Answers

0

If you ran mv file1 newfile and then mv file2 newfile, you irreversibly overwrote newfile. This means your first file is gone.

Practically, there's not a lot you can do in that situation.

Your best option is restoring from your regular backup. You can also pull new SQL dumps, or stop using the system right now and try a file undelete tool. There are plenty for NTFS and FAT, but not that many for ext filesystems. See also:

Also, when working as root, I'd recommend setting the following aliases in your shell's configuration file. This way, you will be prompted before overwriting existing files or removing any file.

[ $UID = 0 ] && \
  alias rm='rm -i' && \
  alias mv='mv -i' && \
  alias cp='cp -i'

Setting aliases for basic commands might bite you at some point if you're getting too used to them, but if you always want a quick reminder before doing potentially harmful stuff, that's the easiest way.

slhck

Posted 2013-03-06T06:27:48.830

Reputation: 182 472

I guess I really messed up here. For the moment I've made new dumps but having the dumps from previous dates were what was important in this case. I don't handle the backups and I'm hoping my coworker has recent ones. Thank you very much for the help. – GUYMESSEDUP – 2013-03-06T07:01:05.413